Composing an Entity Infrastructure Entity Class with a Simple .NET Class

I have the following in the 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

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 steps will work, but inserting or updating is not possible. To get an insert or update, we need to use an ObjectSet <> , but this 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
            });

Is there a good solution for this? This wound was really fantastic.

Ideally, this would be a kind of proxy class that will support all futures, but very customizable ones.

, , .

+3

Source: https://habr.com/ru/post/1789781/


All Articles