Queries inside WHERE condition

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
Mayavi
Posts: 1
Joined: Wed 08 Apr 2009 08:58

Queries inside WHERE condition

Post by Mayavi » Wed 08 Apr 2009 09:06

Hi,

I have a query like this :

var A = from c in Customers
join d in Oreders
Select new
{
CustID = c.CustID,
Oid = d.OrderID
}

So the var A contains some Customer IDs and Order IDs.

Now,

var B = from k in Shop
// In where condition, I need to take all OTHER CustomerIDs and OrderIDs from Shop which is NOT in the var A.

I have used below code, but it is not working...

var B = from k in shop1
join d in shop2 on k.ID equals d.ID
where k.ID != null && d.ID !=null &&
!(from c in A
select c.OrderID).Contains(k.OrderID)
&&
!(from x in A
select x.CustID).Contains(d.CustID)

SELECT NEW
{
// variables.....
}

When I used this query I am getting all the CustomerIDs and OrderIDs....

But I need CustomerIDs and OrderIDs from B and No need to take it if those IDs are already contains in A.

HOW CAN I DO THAT in LINQ ?????

Thanks in Advance, :D

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Thu 09 Apr 2009 09:15

Please look into the generated SQL using the Log property, like in the following code example:

Code: Select all

        StringBuilder sb = new StringBuilder();
        StringWriter sw = new StringWriter(sb);
        dataContext.Log = sw;
        //Your query execution
        Console.Write(sb.ToString());
If anything goes wrong, please let us know about the errors in SQL query generation.
So far we can't reproduce the problem.

Post Reply