[RESOLVED] Entity Framework - specify read only property?
I'm struggling a bit with Entity Framework 4.x. Let's say I have a model called Product. It was generated from a database table. There is a field in this entity called CreatedDate. The MySQL database has a default value for the current timestamp. I don't want Entity Framework to set this field when inserting or update the table. Problem is, I can't seem to figure out how to tell EF to exclude this field from being sent back to the database, but still retain it as a field to be viewable in the application.
Re: Entity Framework - specify read only property?
I'm not sure whether this will work or not but, in the model designer, try selecting that entity property, open the Properties window and then set the Setter to Private.
Re: Entity Framework - specify read only property?
Tried, that didn't work. I actually found the answer through some real digging. Turns out, the way to do it actually doesn't really work. There is some apparent long standing bug in the EF Framework that even though you set the appropriate property in the designer, and it saves it, it doesn't actually update the underlying model "code", so by all appearances, it doesn't work.
The solution is to edit the EDMX file in a text editor, and add StoreGeneratedPattern = "Computed" tag to the property you don't want to insert/update. The "StoreGeneratedPattern" is a property of the entity property in the visual designer, but again, it doesn't update the underlying model for some reason. M$ does seem to have acknowledged this as a bug some time ago, but it has apparently yet to be fixed.