I have an Order table. An Order can have multiple items in it, with each item shipping at different times. I want to get the list of all Orders which excludes partially shipped or orders. In other words, I need to get the list of all orders that are completely shipped. I may know how to do this in T-SQL. But I’m trying to accomplish this with LINQ-to-Entities (EF4/.Net 4.0/C#).
Consider the following Data:
PK OrderID Item Status
1 00001 TV Shipped
2 00001 TABLET Shipped
3 00002 BLURAYPL Not Shipped
4 00002 MOBILEPH Shipped
5 00002 XBOX Shipped
6 00003 PAPER Shipped
7 00003 PENCIL Shipped
The goal is to get 00001 and 00003 as output.
Here is what I have so far, obviously simplified :
using (MyDBEntities dbcontext = new MyDBEntities())
{
var WashingtonClients = from a in dbcontext.CustomerMasterTable
where a.City == "Washington"
select a.CustomerID;
var ShippedOrdersToWashingtonClients = from o in dbcontext.OrderDetail
where WashingtonClients.Contains(o.CustomerID)
&& o.Status.ToUpper() == "SHIPPED"
//how to exclude Partially Shipped orders here???
select o.OrderID;
}
How to frame the second query in such a way that it excludes orders that have even a single unshipped item in it? Many thanks for your time.
Let’s suppose that you have fake list with your data:
Then your linq query should look like this:
so that you get a couple of string –
"00001" and "00003"as a result.Hence for real query to db you can write something like this: