Entities framework mapping association between view and table

前端 未结 1 403
有刺的猬
有刺的猬 2021-01-04 18:01

I can map 1:1 (one-to-one) tables intuitively, like this:

\"\"

But I cannot understand how to do the sa

相关标签:
1条回答
  • 2021-01-04 18:41

    To map an association between two entities, the foreign key can not also be the primary key.

    What you really have here is a TPT inheritance. You have a "base" class, plus optional additional properties in a second table (or view).

    watch this video: http://msdn.microsoft.com/en-us/data/cc765425.aspx

    Make the "view" entity inherit from the Employee entity. Remove the EmployeeID property from the view entity. Map the EmployeeID column of the View to the ID property of the base Employee. You will get a single ObjectSet in your ObjectContext for this hierarchy.

    0 讨论(0)
提交回复
热议问题