What is the syntax for an inner join in LINQ to SQL?

I’m writing a LINQ to SQL statement, and I’m after the standard syntax for a normal inner join with an ON clause in C#. How do you represent the following in LINQ to SQL: select DealerContact.* from Dealer inner join DealerContact on Dealer.DealerID = DealerContact.DealerID 19 Answers 19 It goes something like: from t1 in … Read more

LINQ: When to use SingleOrDefault vs. FirstOrDefault() with filtering criteria

Consider the IEnumerable extension methods SingleOrDefault() and FirstOrDefault() MSDN documents that SingleOrDefault: Returns the only element of a sequence, or a default value if the sequence is empty; this method throws an exception if there is more than one element in the sequence. whereas FirstOrDefault from MSDN (presumably when using an OrderBy() or OrderByDescending() or … Read more

Returning IEnumerable vs. IQueryable

What is the difference between returning IQueryable<T> vs. IEnumerable<T>, when should one be preferred over the other? IQueryable<Customer> custs = from c in db.Customers where c.City == “<City>” select c; IEnumerable<Customer> custs = from c in db.Customers where c.City == “<City>” select c; Will both be deferred execution and when should one be preferred over … Read more