New Posts New Posts RSS Feed: Entity Server Exception using InList with Intersected IEnumerables
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Entity Server Exception using InList with Intersected IEnumerables

 Post Reply Post Reply
Author
pk55 View Drop Down
Senior Member
Senior Member


Joined: 22-Jul-2009
Location: CA
Posts: 105
Post Options Post Options   Quote pk55 Quote  Post ReplyReply Direct Link To This Post Topic: Entity Server Exception using InList with Intersected IEnumerables
    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.

 
Back to Top
pk55 View Drop Down
Senior Member
Senior Member


Joined: 22-Jul-2009
Location: CA
Posts: 105
Post Options Post Options   Quote pk55 Quote  Post ReplyReply Direct Link To This Post 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());
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post 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 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.


Edited by DenisK - 01-Jul-2011 at 4:28pm
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down