Shadow Properties in Entity Framework 7

Sign in to queue

Description

In this short video Rowan describes shadow properties new in Entity Framework 7. This is a super useful feature for those times when your database and your class model don't quite match up. Would love your thoughts!

Here are some links for more information:

As an aside, I spent a couple of days with Rowan (and team) recording additional videos regarding Entity Framework 7 and some of the new features to look for in the coming release. Stay tuned!

Embed

Download

Download this episode

The Discussion

  • User profile image
    andriysavin

    Wow, this is exactly what I need. My scenario is following: in my domain model a have geo coordinates, which are represented by my domain type (because I don't want to have dependency on the DbGeography EF's type). But my repository implementation has need to query the data using geographical filter like distance, so it has to use DbGeography . To solve this problem, I had to create a "shadow" model which was linked to the main model and both were mapped into the same table. When a model instance is being added to the context, I create a shadow model instance, and convert my geography property to DbGeography property in the shadow model, and save them both. I can query the context for main model, but filter by the shadow model. All this machinery (including the shadow model) is hidden in the repository implementation, so the client code doesn't know about it.

    So having shadow properties will simplify my approach valuably, reducing amount of configuration code and removing possible limitations.

    Of course, the ideal solution of my problem would be type conversion support, however, not sure how would model query part work - LINQ statements are written against model, not against (imaginary) converted model.

  • User profile image
    andriysavin

    I'm wondering, can this feature be used to move "row version" property out of a domain model?

  • User profile image
    romiller

    , andriysavin wrote

    I'm wondering, can this feature be used to move "row version" property out of a domain model?

    Yes, that would be a perfect scenario for this feature.

  • User profile image
    afshins

    This was very useful. I just need to know how I can use the value of a shadow property to set another property. This is my scenario: My entity has a List property which I want to store in database in a serialized form (json). I can use a string shadow property to serialize the List property; however, I just don't know how to deserialize it back to the list property.

  • User profile image
    Corneliu

    Ron, Is it possible to use shadow properties to build relations between tables/entities that don't exist in the original model? Like a new one-to-one relation?
    E.g. Blog/BlogDetails?
    I'd like to be able to do:
    OnModelCreating()
    {
    modelBuilder.Entity<Blog>(entity=>{
    entity.Property<BlogDetails>().Metadata.IsShadownProperty = true;
    });
    }
    var q = from b in db.Blogs select b;
    q.Include("BlogDetails") ? or something those lines.
    Thanks.

Add Your 2 Cents