Search code examples
entity-framework-4entity-framework-ctp5

How to map properties in EF CTP5


In CTP 4 we could choose the properties we want to map like so:

    this.MapSingleType(i => new
{
    i.Id,
    i.OriginalFileName,
    i.Extension,
    i.MimeType,
    i.Width,
    i.Height,
    i.ImageStoreLocationId,
    i.AlternateText,
    i.ImageData
});

How do we achieve this in CTP5?

I tried using the following Map configuration but this does not appear to work since I still have to explicitly ignore (this.Ignore(..)) the properties I do not wish to map:

    Map(config =>
{
    config.Properties(i => new
    {
        i.OriginalFileName,
        i.Extension,
        i.MimeType,
        i.Width,
        i.Height,
        i.ImageStoreLocationId,
        i.AlternateText,
        i.ImageData
    });

    config.ToTable("Images");
});

Considering the new API is supposed to be more fluent, it's strange that I have to write more code to achieve the same thing.

Thanks Ben


Solution

  • CTP5 is indeed more powerful and flexible both in Data Annotations and fluent API. For example in CTP4 if we wanted to exclude a property from mapping we would have to explicitly map everything else with MapSingleType in order to skip the one we don't want, like the way you mentioned.
    In CTP5 this can be done simply by using [NotMapped] attribute on the property or by this fluent API code:

    this.Ignore(i => i.Id);
    

    And you are done, no need to invoke Map method.