say, I have a partial class that contains a custom property like this
public partial class Person {
public string ImagePath{get;set;}
}
and I’m using ExecuteStoreQuery<Person> to pull out data, where a stored procedure is executed that joins Person and Image by Person.ImageId = Image.ImageId and gets the ImagePath field from Image table.
This doesn’t seem to work for partial class, but perfectly for inheritance.
However, I don’t want to use inheritant class in this case, so…is it possible for EF to be aware of the partial class’s properties and populate them when executestorequery is executed?
No. If the
Personclass is mapped entity EF uses your mapping in EDMX file and it will populate only mapped properties because none of your custom properties from partial class is part of your mapping.As a workaround create a new class
PersonViewwhich will not be mapped. Add all properties with the same name as columns in you result set and use it inExecuteStoreQuery. In this case EF doesn’t have mapping for the new class in EDMX so it will infer the simplest mapping – it will pair columns and properties by name.