Entity framework entity class mapping with plain .net class
- by Elan
I have following in entity framework
Table - Country
Fields
List item
Country_ID
Dialing_Code
ISO_Alpha2
ISO_Alpha3
ISO_Full
I would like to map only selected fields from this entity model to my domain class.
My domain model class is
public class DomainCountry
{
public int Country_ID { get; set; }
public string Dialing_Code { get; set; }
public string ISO_3166_1_Alpha_2 { get; set; }
}
The following will work however insert or update is not possible. In order to get insert or update we need to use ObjectSet< but it will not support in my case.
IQueryable<DomainCountry> countries =
context.Countries.Select(
c =>
new DomainCountry
{
Country_ID = c.Country_Id,
Dialing_Code = c.Dialing_Code,
ISO_3166_1_Alpha_2 = c.ISO_3166_1_Alpha_2
});
It will be really fantastic could someone provide a nice solution for this.
Ideally it will be kind of proxy class which will support all the futures however highly customizable
i.e. only the columns we want to expose to the outer world