Page 1 of 1

Bulk fetches with In operator. How to?

Posted: Wed 16 Jun 2010 11:46
by Settler
Hi.

I try to write this SQL query in LinqToSql:

Code: Select all

SELECT *
FROM directive_line t1
WHERE (t1."Id", t1."IdSomeOther") in ((13, 10), (11, 9))
I try this LinqToSql code:

Code: Select all

public class ObjectForQuery
{
    public long Id{get;set;}
    public long IdSomeOther{get;set;}
}

....

var objectsForSearch = new List
{
    new ObjectForQuery{Id = 13, IdSomeOther = 10},
    new ObjectForQuery{Id = 11, IdSomeOther = 9},
};

var list = (from directiveLineDB in context.DirectiveLines
where objectsForSearch.Select(o => new {o.Id, o.IdSomeOther }).Contains(new { Id = directiveLineDB .Id, IdSomeOther= directiveLineDB.IdSomeOther})
select directiveLineDB).ToList();
But i got System.InvalidOperationException:
"Could not format node 'New' for execution as SQL."

I'm do something wrong? How can I write this sql query in Linq?

dotConnect for PostgreSQL: 4.65.79.0

Posted: Mon 21 Jun 2010 16:01
by Shalex
I have successfully executed your code using the Dept table with the 4.95.140 version of dotConnect for PostgreSQL. The SQL from DbMonitor:
SELECT t1.deptno, t1.dname, t1.loc
FROM public.dept t1
WHERE ((t1.deptno = :p0) AND (t1.dname = :p1)) OR ((t1.deptno = :p2) AND (t1.dname = :p3))

Please upgrade to the 4.95.140 version. If this doesn't help, send us a small test project with your model and the DDL/DML script of your database objects.