Given a many to many relationship ( one customer has many Reservations and a Reservation can belong to more than one customer)
Customer Reservation
Whats the easiest way to query Customers and their corresponding Reservations and vica versa ( Using linq to entities)
There is a great example of a single hop:
var query = from it in context.products.Include("ProductCategories")
orderby it.productcategories.CategoryName, it.ProductName
select it;
I want to be able to navigate from one entity to another no matter how far the relation is.
Easiest way to query relational data
You can use Include like in the following code sample:
Code: Select all
from t1s in db.T1.Include("T2").Include("T2.T1") select t1s;
Thank you
That works. And for anyone else interested, Include key word is eager loading, so it will immediately load those into the framework.AndreyR wrote:You can use Include like in the following code sample:Code: Select all
from t1s in db.T1.Include("T2").Include("T2.T1") select t1s;