How exactly is ServiceStack OrmLite handling default and computed columns?
Specifically I'm getting the error
The column "PointsAvailable" cannot be modified because it is either a computed column or is the result of a UNION operator.
This column is configured as a computed column in an SQL Server 2008 database.
OrmLite does seem to do something with computed columns as you can add the attribute '[ServiceStack.DataAnnotations.Compute]' to a property in a model.
Stepping into the code, the function 'ToInsertRowStatement' in 'OrmLiteDialetBase.cs' is called. While that function is checking if the AutoIncrement property is set, it isn't checking if the IsComputed property is set.
I don't know if this is a bug or if I'm just using it wrong.
For my computed columns which are only computed in the service layer, SQL knows nothing about them, so I used a combination of the following attributes on the servicestack model:
[Compute, ServiceStack.DataAnnotations.Ignore]
public List<MyModel> MyList {get;set;}
The difference seems to be the "Ignore" attribute which insisted upon having it's namespace attached ??. With these in place, my basic queries run, otherwise SQL complains that the columns don't exist - rightly enough!
You can, as suggested by t-clausen.dk use an SQL Filter by specifically passing an SQL CommandText string with all the column names you do want, but I think that opens a maintenance issue.
As for a bugfix that looks at the database, it appears the the SQL is generated on a per-provider basis by a "toSqlString()" or similar method. So there are probably a few spots to pay attention to...
EDIT: It is simply the Ignore attribute which does the job. From the source:
/// IgnoreAttribute
/// Use to indicate that a property is not a field in the table
/// properties with this attribute are ignored when building sql sentences
There is also the option to use an ALIAS which I've not explored.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With