EF populate data for properties in partial classes which are not created by EF
HI I need to get some extra information when i retrieve data for an entity. However the extra properties are 开发者_如何转开发in different tables. I created a partial class with these extra properties. How do i get EF to populate the extra properties.
thanks
You must populate them manually. Once properties are not part of mapped entity (which they probably cannot be) EF will not do anything with them because it doesn't know them.
Another way is not using your original entity and use some custom Linq-to-entities query filling either not mapped or anonymous type. The last option is using special read only entity defined in your entity model and manually create QueryView in your EDMX file.
Following up to Ladislav's post. The easiest way? Create a model/class containing the properties you need this essentially acts as a db view then when you send your model to your view you can use linq and join then cast it to the view model/object.
var m = (your models joined).select(x=> new Model(properties....))
.(First<Model>(), AsEnumerable<Model>(), etc);
精彩评论