EF Core fluent mapping to inner object properties

丶灬走出姿态 提交于 2019-12-05 09:55:48

EF Core doesn't support this type of mapping for now. It will not be supported in EF Core 1.0 RTM (see my github issue : https://github.com/aspnet/Home/issues/1330)

As I described in my github issue, I figured out 2 solutions :

1) Create a derived class from my model, specialy designed for EF, and expose all properties as simple. It will need more mapping when insert/update and retrieve from Db. We don't choose this option

2) Create proxy properties. In my example, this is like :

public class MyEntity {
   private MySubEntity SubEntity {get; set;}
   public string SubEntityValue 
   { 
     get 
     { 
         return SubEntity.Value;
     } 
     set 
     { 
         SubEntity.Value = value; 
     }
}

This seems to be the best solution (we choose this one).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!