I have Order – Customers table
i am using lazyloading for pulling order-customers information.
var ordercustomer = db.Orders.Include("customers").Where(c.orderid == id);
so i have pulled a ORDER WITH RELATED CUSTOMERS
I HAVE CUSTOMERID ,CUSTOMERCITY VALUES from the Form values
NOW MY TASK IS to check whether customerid and customercity exist in the
ordercustomer (result of the linq)
how would the linq query looks like?
I think you’re asking for something like this:
This will produce a true or false value that tells you whether the given order has a customer associated with it that has the given ID and city. If the order doesn’t exist, an exception will be thrown.
On a side note, when use use
.Include, that is called eager loading. It is the opposite of lazy loading. Also, note that your original query doesn’t actually have any of the customers loaded yet because you haven’t evaluated it by calling.ToListor something similar. In the query I’ve provided, you aren’t required to use.Includebecause there is no reason to load all the Customer data into memory, when the database can do this work for you.