Map derived type to the same table in EF

后端 未结 3 1369
刺人心
刺人心 2021-01-23 23:11

The following simple code example illustrates the scenario in question. I have a Person entity, which is simply mapped to the Person table in the DB. I am using the default Enti

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-23 23:21

    Have you tried using composition instead of inheritance?

    public class PersonViewModel {
      public Person Person { get; }
      public int? MyViewProperty { get; set; }
      // ...
    }
    

    Unless there's a really good reason I would never transfer that object to your service however. To me that looks like a client side object only. What's the point of having GUI properties transmitted to the server when they're not stored in the database anyway? Isn't it enough to just get the Person and send that to the server for update?

提交回复
热议问题