That LINQ Error…

In today's webcast on LINQ in C# we looked at joining XML data with SQL Server and we got the error "Local sequence cannot be used in LINQ to SQL implementation of query operators except the Contains() operator" when we tried to run it. Looking deeper into what happened, it appears that the order in which collections are joined in LINQ is important. The original code looked like this:


What I found is that we need to specify that we're working with the XML resultset v in venues first and then join to e in events...basically reverse the order that the joined set linqs the two:



Comments (1)
  1. Keith Farmer says:

    What’s weird about it?  Take a look in Reflector and you’ll probably see the root of the matter.  Basically, it’s a difference in asking LINQ to SQL to join to an XML result, or LINQ to XML to join to a LINQ to SQL result.

    Incidentally, why are you defining var events?  There’s neither filtering nor reprojection, so dc.Events would be just fine.

Comments are closed.

Skip to main content