I am attempting to try to use the following Linq query to pull for multiple values of 'ID'. Instead of creating a complicated LINQ query with numerous 'where' clauses, is it possible to query against only the ID values in a collection object?
My Collection is an ArrayList object - it contains various ID values we will query for
My Linq Query: // Query the Table IQueryable query = from c in Table where c.ID == System.Convert.ToInt32(arrProviders[i]) select new { c.Number, c.FName, c.LName };
I am still struggling with this question. Can someone please help? Here is my most updated code throwing an error. Basically I am trying to Select records from a SQL Table based on the ID value stored in an ArrayList object.
LINQ Query Code: from c in customers.AsQueryable() join p in arrSet.Cast<Order>() on c.ID.Value.ToString() equals p.ID.ToString() select new { c.FirstName, c.LastName };
Error Message I am receiving: Local sequence cannot be used in LINQ to SQL implementation of query operators except the Contains() operator.
The trick seems to be that you can not make a join between a Custom Class collection and a LINQToSQL query. Anyway, you can make it using a List(Of integer) so here's a suggestion for you :
1. Create a temporary query to hold every OrderId (as integer values) : 2. Using the correct syntax, make the query on customers using the CONTAINS statement on your list of OrderID...
I did it with VisualBasic and worked fine. Hope this helps!
1:
2:
3:
qry = From c in customers.AsQueryable() _
Where ( From o In arrSet Select o.Id).ToList().Contains(c.Id) _
select new { c.FirstName, c.LastName };