Entity Framework Model First: how to create association with properties

寵の児 提交于 2019-12-14 03:42:55

问题


I am trying to create data model for a graph with Node and Edge. If Edge does not contain any property I can simply create many-to-many association from a Node to itself. However I want to store some properties on the Edge e.g. Distance. I tried to create another entity but didn't find a way to declare the relationship between Edge and Node. Is it possible in Model First? How?


回答1:


You must create two one-to-many associations from Node to Edge to model self referencing many-to-many relation with mapped junction table. In terms of graph theory EF models creates oriented graph so it differs between edge from A to B and from B to A.

You will start with your two entities and their properties:

You will drag the first Association from Toolbox. Start at Node and drag association to Edge - it will create one-to-many relation between Node and Edge. Configure properties of created navigation for "Outgoing" edges:

You will drag the second Association in the same way and configure its properties for "Incoming" edges:

After generating a database from this model you will get this table structure:



来源:https://stackoverflow.com/questions/9043453/entity-framework-model-first-how-to-create-association-with-properties

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