Print Page | Close Window

Entity Server Exception using InList with Intersected IEnumerables

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2807
Printed Date: 24-Jan-2026 at 4:39pm


Topic: Entity Server Exception using InList with Intersected IEnumerables
Posted By: pk55
Subject: Entity Server Exception using InList with Intersected IEnumerables
Date Posted: 30-Jun-2011 at 8:04pm

Getting another exception when I execute a query that uses a predicate description built with a FilterOperator of InList when the list is an intersected set of lists:

RemoteExceptionDetails:
System.ArgumentException: Invalid values for InList operation - Value must be of type: System.Collections.Generic.IList`1[System.Int32]
     at IdeaBlade.Linq.PredicateDescription.Validate()
     at IdeaBlade.Linq.PredicateDescription.Initialize(FilterOperator filterOp, Object value, Boolean ignoreCase)
     at IdeaBlade.Linq.PredicateDescription..ctor(Type instanceType, String propertyPath, FilterOperator filterOp, Object value, Boolean ignoreCase)
     at IdeaBlade.Linq.PredicateBuilder.Make(Type type, String propertyName, FilterOperator filterOp, Object value)
 
I have several queries that produce a set of distinct values and return their results into an IEnumerable<int>.  If I just use this one single list of values in the predicate description, it works fine but if I combine them via the Intersect operation, it throws the error.  All of these are server-side sync queries.
 
Take these obviously made-up queries to illustrate this against NorthwindIB:
 
// SQL
select Distinct ProductID from [Product] where UnitsInStock < 5
intersect
select Distinct ProductID from [Product] where CategoryID < 5
 
// and now DevForce
IEnumerable<int> productsFromUnits;
IEnumerable<int> productsFromCategoryull;
IEnumerable<int> commonProducts;
var propSelector = new PropertyProjectionSelector(typeof(Product), "ProductID");

productsFromUnits = EntityQuery.Create(typeof(Product)).Where(x => x.UnitsInStock < 5).Select(propSelector).Distinct().Execute().Cast<int>());

productsFromCategory = EntityQuery.Create(typeof(Product)).Where(x => x.CategoryID < 5).Select(propSelector).Distinct().Execute().Cast<int>());
 
commonProducts = productsFromUnits.Intersect(productsFromCategory);
 
var p = PredicateBuilder.Make(typeof(Product), "ProductID", FilterOperator.InList, commonProducts);
var q = EntityQuery.Create(typeof(Product).Where(p);
var results = manager.ExecuteQuery(q);
Again, I'm using build 6.1.2.0c.

 



Replies:
Posted By: pk55
Date Posted: 30-Jun-2011 at 8:38pm

Just to clarify that it will work if I add a ToList to the final combined list but this works in Linqpad without that last step so I still think it's a bug (just not as urgent :-) 

var p = PredicateBuilder.Make(typeof(Product), "ProductID", FilterOperator.InList, commonProducts.ToList());


Posted By: DenisK
Date Posted: 01-Jul-2011 at 4:26pm
Hi pk55;

Thanks for the repro. It makes it easier to create the unit test for this. I've submitted a bug report and as usual, I will update you with a patch if you require it.

I saw that you also posted a similar issue here.  http://www.ideablade.com/forum/forum_posts.asp?TID=2806&title=entity-server-exception-creating-predicatedescription-with-inlist-operator-on-nullable-db-properties - http://www.ideablade.com/forum/forum_posts.asp?TID=2806&title=entity-server-exception-creating-predicatedescription-with-inlist-operator-on-nullable-db-properties

I believe this is the same bug.

EDIT: Oops, sorry the exception looks similar but it's NOT the same bug. Let me take a look at that as well.


Posted By: DenisK
Date Posted: 11-Jul-2011 at 1:23pm
Hi pk55;

It turns out that this is not a bug. The exception that we're getting is correct.

RemoteExceptionDetails: 
System.ArgumentException: Invalid values for InList operation - Value must be of type: System.Collections.Generic.IList`1[System.Int32]

you need to call commonProducts.ToList() because commonProducts is an IEnumerable and not an IList.



Print Page | Close Window