The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'Join'.

by Tom Hundley 20. May 2010 11:58

Let’s start by saying the code in this example is a really silly, but it’s a great reference for the matter at hand.  Let’s assume you need to do a join on multiple columns and you’ve double checked and triple checked that the types are all the same, but you’re stuck with the following error:  The type of one of the expressions in the join clause is incorrect.  Type inference failed in the call to 'Join'.  The problem is related to anonymous types.  The type initializer cannot infer the same anonymous type because the names are not the same.  The solution is simple: specify the name in one of the expressions such that they are the same and the problem is solved.

 

Problem Code:

image

 

 

Solution:

image

 

Now that the types AND the *names* are the same, the anonymous type initializer can create the same anonymous type and properly facilitate the join.

 

Happy coding,

 

Tom Hundley

Elegant Software Solutions, LLC

 

Reference:

Thanks to Matt Warren from Microsoft:

http://social.msdn.microsoft.com/Forums/en-US/linqprojectgeneral/thread/bf98ec7a-cb80-4901-8eb2-3aa6636a4fde

Tags: , , ,

C# | Linq

type used in a using statement must be implicitly convertible to 'System.IDisposable'

by Tom Hundley 20. May 2010 11:37

If you are using “using” statements to manage your data contexts in Linq to SQL (I’m not sure if this applies to Linq to Entity but I imagine it does") and you get the following error: “type used in a using statement must be implicitly convertible to 'System.IDisposable'”, simply add a reference to the “System.Data.Linq” assembly and it solves the problem.

image

 

Happy coding,

Tom Hundley
Elegant Software Solutions, LLC

Tags: , ,

C# | Linq