Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between a Navigation Property and an Association in EF?

I use EF4.

Hope my question is not too trivial:

What is the difference between a Navigation Property and an Association in EF?

If you could give me a simple explanation with an example would be great thanks!

like image 335
GibboK Avatar asked Jun 24 '11 15:06

GibboK


People also ask

What is a navigation property in EF?

A navigation property is an optional property on an entity type that allows for navigation from one end of an association to the other end. Unlike other properties, navigation properties do not carry data.

What is navigation property in Linq?

Navigation properties allow a user to navigate from one entity to another, or from one entity to related entities through an association set. This topic provides examples in query expression syntax of how to navigate relationships through navigation properties in LINQ to Entities queries.

What are scalar and navigation properties in Entity Framework?

Basically a scalar property is mapped to a column (int, string, ...) A navigation property is mapped to a relation. e.g Order. OrderDetails brings you to all ORderDetails of a specific order.

What are the types of property in Entity Framework?

An Entity can include two types of properties: Scalar Properties and Navigation Properties. Scalar Property: The type of primitive property is called scalar properties. Each scalar property maps to a column in the database table which stores the real data.


1 Answers

An association is the definition of a relationship between two entity types (ala a foreign key)

A navigation property really is a property that allows you to traverse from one end of an association to the other.

Edit: Sorry you wanted an example.

Take a look at this MS documentation. It makes it pretty clear the difference.

Navigation Properties

Association Types

To blatantly inline their documentation (self hosted the images):

Association

PublishedBy and WrittenBy are associations. They tie together Book/Publisher and Book/Author (ala foreign keys)

Navigation Property

Notice Books in the Publisher and Author entities. This "navigation property" allows you to traverse back to the book entity and retrieve it's information as well. (Author.Books.Title for example)

Hope that explains it!

like image 168
Khepri Avatar answered Oct 14 '22 05:10

Khepri