Skip to content
Advertisement

Tag: linq

Error in LINQ to SQL: specified cast is not valid

Hi I am trying to learn LINQ, and in LINQ to SQL I have got following exception: This is a sample code from Linq In Action by Manning publications. Whats wrong? Exception details: Answer If my memory serves, the Customers table in Northwind does not have CustomerID as int (I think its NVARCHAR). If you wrote the Contact class manually,

Sql Query to Linq

How would I convert this query from SQL to Linq: Update Thanks Guys, this is the code I used. Tested and returns the same as above: Answer I don’t know if the syntax is correct (especially the last two lines) but it should be pretty close. I added the 0 between group and by based on Eamon Nerbonne’s correction in

How can you handle an IN sub-query with LINQ to SQL?

I’m a bit stuck on this. Basically I want to do something like the following SQL query in LINQ to SQL: Any help would be gratefully received. Answer Have a look at this article. Basically, if you want to get the equivalent of IN, you need to construct an inner query first, and then use the Contains() method. Here’s my

Advertisement