Bulk fetches with In operator. How to?

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
Settler
Posts: 19
Joined: Mon 01 Mar 2010 16:32

Bulk fetches with In operator. How to?

Post by Settler » Wed 16 Jun 2010 11:46

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

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Mon 21 Jun 2010 16:01

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.

Post Reply