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!
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.
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.
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.
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.
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):
PublishedBy and WrittenBy are associations. They tie together Book/Publisher and Book/Author (ala foreign keys)
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With