I want to join two tables with lambda expressions: Order and OrderLogistics.
Order looks like this:
public class Order{
public int ID { get; set; }
}
And OrderLogistics looks like this:
public class OrderLogistics{
public int ID { get; set; }
public int OrderID { get; set; }
}
I want to join them with Order.ID and OrderLogistics.OrderID.
I do not understand how the queries in this question will be used. Lambda Expression for join
The only way of writing a query I know is:
IQueryable<Order> listOfRecentOrders = Orders
.Where(x => x.OrderLogistics.DepartureDate == date
&& x.TypeID != 4
&& x.TypeID != 5
&& x.StatusID != 8
&& x.StatusID != 9
&& x.StatusID != 10
&& x.Customer.ID != null
&& x.IsDeleted == false
&& x.OrderLogistics.DepartureTime >= 100
&& x.OrderLogistics.DepartureTime <= 2400)
.OrderBy(x => x.OrderLogistics.DepartureTime)
.Take(8));
I do not get what they are doing with a 'var query'. How do I use that in MVC? The above method is inside my repository and the result will be passed on to the controller.
So what I want is a query where I can use properties of Order AND properties of OrderLogistics. My own query above doesn't work because the relationship "x.OrderLogistics" does not exists.
EDIT: And I have:
IQueryable<Order> listOfRecentOrders =
And:
var joined2 = from p in Order
join pType in OrderLogistics
on p.ID equals pType.OrderID
select (x => x.Order);
How do I assign joined2 to listOfRecentOrders? I don't see this ANYwhere in all query questions. This is the MOST important part.
PROBLEM: I need to do a query where I JOIN two tables. This I want to put inside a list and pass this list to the controller so I can use the data in my view.