I'm trying to create a query which uses a list of ids in the where clause, using the Silverlight ADO.Net Data Services client api (and therefore Linq To Entities). Does anyone know of a workaround to Contains not being supported?
I want to do something like this:
List<long?> txnIds = new List<long?>();
// Fill list
var q = from t in svc.OpenTransaction
where txnIds.Contains(t.OpenTransactionId)
select t;
Tried this:
var q = from t in svc.OpenTransaction
where txnIds.Any<long>(tt => tt == t.OpenTransactionId)
select t;
But got "The method 'Any' is not supported".
In addition to selected answer.
Replace
Expression.Or
withExpression.OrElse
to use with Nhibernate and fixUnable to cast object of type 'NHibernate.Hql.Ast.HqlBitwiseOr' to type 'NHibernate.Hql.Ast.HqlBooleanExpression'
exception.I'm not sure about Silverligth, but in linq to objects i always use any() for these queries.
Here's an example where I demonstrate how to write set-based queries using the DataServiceContext : http://blogs.msdn.com/phaniraj/archive/2008/07/17/set-based-operations-in-ado-net-data-services.aspx
You can fall back on hand coding some e-sql (note the keyword "it"):
Here is the code that I used to generate some e-sql from a collection, YMMV:
I think a Join in LINQ can be a walkaround.
I haven't tested the code though. Hope it helps. Cheers. :-)
Join in LINQ:
http://weblogs.asp.net/salimfayad/archive/2008/07/09/linq-to-entities-join-queries.aspx
From MSDN:
and the query becomes: