What are the Navigation Properties in Entity Framework

喜欢而已 提交于 2020-06-25 00:13:51

问题


I am new to Entity Framework. When the Visual Studio creates Model diagram we can see mainly two things in Entities.Propertie and Navigation Properties,So what are these Navigation Properties? How to use them?


回答1:


Navigation properties represents related entites to the principal entity. Foreign Keys are usually represented by navigation properties.

Ex : if you have two tables Invoice and invoice items and those tables have a relation 1-> many so you'll find a navigation property in invoice entity that lists all invoice items related to an invoice.
Hope it helps.




回答2:


Navigation properties in the Entity Framework provide a way to navigate an association between two entity types. Every object can have a navigation property for every relationship in which it participates. Navigation properties allow you to navigate and manage relationships in both directions, returning either an EntityReference, if the multiplicity is either one or zero-or-one, or an EntityCollection, if the multiplicity is many.

When you use the Entity Framework-generated classes, navigation properties are created for objects that participate in a relationship.

UPDATE: Here is nice navigation properties example for relations between books, authors and publishers.




回答3:


Navigation Property is mainly used for Foreign key relationship in EF. i.e. User to Roles, product to categories etc.

so if you have Order with OrderLines, navigation property will say Order_OrderLineItems and you can access complete line items associated with it.

have a look some of the explanation here, What are Navigation Properties in Entity Framework for?



来源:https://stackoverflow.com/questions/11508103/what-are-the-navigation-properties-in-entity-framework

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