Page 1 of 1

.Contains supported?

Posted: Thu 08 Jan 2009 17:00
by Co
When we attempt to use Collection.Contains in EF we get an error that this is not supported by the store. Currently we using version 5.00 of dotConnect.

example:
string[] list=new string[]{"test","test2"};
IQueryableresult = from p in Context.ITEM
where list.Contains(p.NAME)
select p;

Above snippet is not the exact example since i'm at home right now..
The desired effect is that above code will be executed as an ORACLE IN statement.
Please let me know what is the wat to go

Posted: Fri 09 Jan 2009 07:50
by AndreyR
This feature is not supported by Microsoft LINQ to Entities.

Posted: Fri 09 Jan 2009 07:57
by Co
Do you know of an alternative way to accomplish the wanted behaviour

Posted: Fri 09 Jan 2009 11:02
by AndreyR
Unfortunately, we are not aware of any way to use .Contains() with LINQ to Entities.
As an alternative, you can try LINQ to Oracle. I managed to execute the previous code without changes using LINQ to Oracle.

Posted: Fri 09 Jan 2009 13:59
by AndreyR
There is a workaround, but it's not optimal though.
You can write an exspression that can in some implement the functionality of the Contains method yourself, like following:

Code: Select all

        List list = new List{ "RESEARCH", "ACCOUNTING", "test"};
    
        ParameterExpression d = Expression.Parameter(typeof(DEPT), "d");
        MemberExpression dname = Expression.PropertyOrField(d, "DNAME");
        ConstantExpression listMember;
        BinaryExpression compare;
        BinaryExpression or = null;
        foreach (string s in list) {
          listMember = Expression.Constant(s, typeof(string));
          compare = Expression.Equal(dname, listMember);
          if (or == null)
            or = compare;
          else
            or = BinaryExpression.Or(or, compare);
        }
        Expression> lambda = Expression.Lambda>(or, d);
and then execute query like this:

Code: Select all

        var result = db.DEPT.Where(lambda); 
This code is for the Dept table, hope it helps.

Posted: Fri 09 Jan 2009 15:00
by Co
Thanx we'll give it a go..

Posted: Mon 12 Jan 2009 23:10
by mpovidlov
AndreyR wrote:Unfortunately, we are not aware of any way to use .Contains() with LINQ to Entities.
As an alternative, you can try LINQ to Oracle. I managed to execute the previous code without changes using LINQ to Oracle.
How can one use LINQ to Oracle? I always "Add ADO.NET Entity Data Model" and then use LINQ to the generated Entity classes. Does it mean that I am using LINQ to Entities? Can you give an example please?

Posted: Tue 13 Jan 2009 08:54
by AndreyR
You can read about both LINQ to Entities and LINQ to SQL (LINQ to Oracle is Oracle-specific implementation of LINQ to SQL) here:
http://msdn.microsoft.com/en-us/library/cc161164.aspx
When adding ADO.NET Entity Data Model you will always use LINQ to Entities.
But you can use Devart Entity Developer for generating a .dbml model and using LINQ to generated classes.

MSDN has a generic way of solving this

Posted: Fri 23 Jan 2009 20:49
by HintonBR
There is a post on MSDN for a generic method that can be reused for Contains - http://social.msdn.microsoft.com/forums ... 4a1ab59f0/
________
LIST OF TRANSMISSIONS