EntityFramework how to Override properties
I've just started using EF in VS2010. That thing is just amazin'.
I frankly can't understand something. For example I have EntityType with property, they generated from database structure. Now, I have to simply override that property in my code. I don't need to save value of the property back into DB, but everytime when it gets read from DB it should be substituted with run-time calculated value.
Of course I can create derived class based on my EntityType but I'v开发者_如何学编程e tried and found kinda difficulties, I'm not sure this is kinda right way to do. Anyway even when I try to change the whole EntityType to Abstract, damn Visual Studio doesn't want to validate that and says something like:
"Error 2078: The EntityType 'AssetsModel.Asset' is Abstract and can be mapped only using IsTypeOf." "Error 2063: At least one property must be mapped in the set mapping for 'Assets'"
What the hell is this suppose to mean I dunno..
Any ideas?
The best approach would be to use Partial Classes and then create a new ReadOnly property to calculate the value in the getter.
精彩评论