How to create a relationship between table and view in the Entity Framework

前端 未结 1 1117

I have an Entity Framework model that was generated by the Visual Studio 2008 wizard based on a Sql Server 2008 database.

The model has a view that logically is joined

相关标签:
1条回答
  • 2021-02-14 09:08

    Yes, you can do this, but the GUI designer won't be able to infer it for you.

    The first thing the need to do is configure the view correctly. The designer cannot infer the primary key, so you will need to supply that information.

    You can now right-click in the empty space in the designer and then choose to add an association. Define the association between your view and table, setting the cardinality correctly.

    In EF 1, you will need to remove the FK fields from the client schema by selecting them in the designer and pressing delete. This is because, in EF 1, you cannot have the same field mapped to both an association and in a scalar property. In EF 4, you can keep the FK fields if you use FK associations, or you can use independent associations which behave like EF 1.

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