简体   繁体   中英

EF 4.1 trying to set the value of a computed column

I am using EF 4.1 and SQL server 2008 with the ADO.net DBContext generator that generates my model pocos. I have a database table with 2 computed columns and in my edmx file the mapped properties are both have "Computed" set for the StoreGenerationPattern option. Yet when i insert an entity as below

MyDbContext.Events.Add(oEvent);
MyDbContext.SaveChanges();

it generates a SQL insert statement that tries to insert nulls into the computed columns.

Anybody any idea what is going on?

OK i have sussed this now and it boils down to my ignorance of how EF works. I was passing my DbContext an ordinary ADO.net connection string which seems to flip it into code first mode. As such any settings and configuration in my edmx model were ignored and it was looking for attributes on the model classes. As soon as i changed it to use an EF string that includes references to the model metadata files it works. Seems obvious now, no idea how i expected it to magically know about model metadata.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM