简体   繁体   English

实体框架中的导航属性是什么

[英]What are the Navigation Properties in Entity Framework

I am new to Entity Framework. 我是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? 当Visual Studio创建模型图时,我们可以在Entities.Propertie和Navigation Properties中看到两件事,那么这些导航属性是什么? How to use them? 怎么用?

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. 例如:如果您有两个表发票和发票项目,并且这些表格具有1->多的关系,那么您将在发票实体中找到列出与发票相关的所有发票项目的导航属性。
Hope it helps. 希望能帮助到你。

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. 导航属性允许您在两个方向上导航和管理关系,如果多重性是一个或零或一,则返回EntityReference,如果多重性为多,则返回EntityCollection。

When you use the Entity Framework-generated classes, navigation properties are created for objects that participate in a relationship. 使用Entity Framework生成的类时,将为参与关系的对象创建导航属性。

UPDATE: Here is nice navigation properties example for relations between books, authors and publishers. 更新:以下是书籍,作者和出版商之间关系的很好的导航属性示例

Navigation Property is mainly used for Foreign key relationship in EF. Navigation属性主要用于EF中的外键关系。 ie 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. 因此,如果您使用OrderLines订购,则导航属性将显示Order_OrderLineItems,您可以访问与其关联的完整行项目。

have a look some of the explanation here, What are Navigation Properties in Entity Framework for? 看看这里的一些解释, 实体框架中的导航属性是什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM