Assuming i have an array of People (it is an entity in the Database, generated via the edmx).
I want to add a new field to the entity (an unbound calculated field).
What should i do? Create a new class that will inherit from the People entity with the new field ? Using partial class ? How to fill the new colum in the array ?
Thanks Jonathan
I would create a partial class and add the property there. However, in order to use it in linq queries, you need to fetch the elements from the db. So, you could do this
entities.People.ToList().Sum(p=>p.CalculatedField);
While this wouldn't work
entities.People.Sum(p=>p.CalculatedField);
B/c there's no way for linq to translate that into SQL
Entity framework generates partial classes for all entity objects. You can add whatever properties you like by adding them to the partial class with the same name as the generated class. As @Gervasio mentioned you would have to manually populate the property through code. I posted a similar answer here: Implement OnRaisePropertyChanged on partial class
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.