.Contains supported?

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
Co
Posts: 15
Joined: Fri 28 Nov 2008 10:59

.Contains supported?

Post by Co » Thu 08 Jan 2009 17:00

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

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

Post by AndreyR » Fri 09 Jan 2009 07:50

This feature is not supported by Microsoft LINQ to Entities.

Co
Posts: 15
Joined: Fri 28 Nov 2008 10:59

Post by Co » Fri 09 Jan 2009 07:57

Do you know of an alternative way to accomplish the wanted behaviour

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

Post by AndreyR » Fri 09 Jan 2009 11:02

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.

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

Post by AndreyR » Fri 09 Jan 2009 13:59

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.

Co
Posts: 15
Joined: Fri 28 Nov 2008 10:59

Post by Co » Fri 09 Jan 2009 15:00

Thanx we'll give it a go..

mpovidlov
Posts: 20
Joined: Tue 06 Jan 2009 00:34
Location: US

Post by mpovidlov » Mon 12 Jan 2009 23:10

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?

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

Post by AndreyR » Tue 13 Jan 2009 08:54

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.

HintonBR
Posts: 24
Joined: Mon 16 Jun 2008 17:07

MSDN has a generic way of solving this

Post by HintonBR » Fri 23 Jan 2009 20:49

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

Post Reply