Ignore Columns on ModelUpdate

Mar 9, 2015 at 3:10 AM
I have removed and added some columns as computed columns using custon SQL, everyting is ok untill i restart the application. The VITA detects that the model is changed and tries to alter the table but it cannot change a computed column, so is there a way to ignore if the changed columns are computed columns?

Thanks
Coordinator
Mar 9, 2015 at 4:18 AM
that's not supported, yet, but I'll add this asap, try to push it this coming week. Thank you, you and other guys for letting me know which things should be fixed first! this all becomes a priority.
Roman
Coordinator
Mar 12, 2015 at 7:49 PM
I've added a workaround allowing you to have a db-computed column in the database. You add the column manually in database, after the table is created initially, then add a matching property to entity definition decorated with AsIs and NoInsertUpdate attributes:
// Example of DB-computed columns (workaround); you create column directly in database on existing table, manually (MsSql only): 
//  ALTER TABLE [books].[Book] ADD SelectedOn AS (GetDate());
// and then tell VITA to accept column as-is, not trying to update it's definition, or insert/update values
[AsIs, NoInsertUpdate]
DateTime SelectedOn { get; }
I've tried it on IBook entity in sample BookStore app, seems to be working. AsIs tells VITA to not attempt to modify column definition in any way; NoInsertUpdate prevents from trying to set its value.
Will be there over weekend in the new version
Roman
Mar 12, 2015 at 8:22 PM
Ok, Thanks,

Just one thing, will VITA create the column in the initial create table?

Regards,
Coordinator
Mar 12, 2015 at 8:23 PM
no, you start without property, let VITA create table, then manually add the column in DB and add matching property in entity
Mar 12, 2015 at 8:40 PM
A better solution wold be, if the column does not exist, create it, if it exists do not touch it.

The problem with your solution is that it only works if you already have a database when i install the application.

Regards
Coordinator
Mar 12, 2015 at 8:48 PM
question - who will create real computed Db column when you install the app?
anyway, I will think about this. Also, this is a temp workaround, definitely must be direct support for this in the future.
Mar 12, 2015 at 8:54 PM
The columns will be created or deleted/recreated by a script after the application 1st start.

So if VITA simply ignores the column in the create but then reads the values after the script that is the perfect solution ;)

Regards
Coordinator
Mar 13, 2015 at 7:42 PM
Ok, just tested it, it will work for new database. VITA would create a new normal column first; then custom script deletes it and creates Db-computed column; after app restart VITA will leave it as is. The only extra requirement is to have Nullable attribute on the property:
// Example of DB-computed columns (workaround); you create column directly in database on existing table, manually (MsSql only): 
//  ALTER TABLE [books].[Book] ADD SelectedOn AS (GetDate());
// and then tell VITA to accept column as-is, not trying to update it's definition, or insert/update values
// For initial db creation or if column does not exist, it will be created as normal data column - but the property must be marked as Nullable. 
//  Custom install script might later drop the column and create db computed column. VITA will not try to change the column after that.  
[AsIs, NoInsertUpdate, Nullable]
DateTime SelectedOn { get; }
Mar 13, 2015 at 9:09 PM
Fantastic :)

Thanks.
Mar 16, 2015 at 2:54 PM
Tested this and it is working perfectly

Thanks,