0

I am getting data from a table by applying join on two tables but i am getting this error:

Error   40  The type of one of the expressions in the join clause is incorrect.  Type inference failed in the call to 'Join'.   C:\Documents and Settings\Ashir\My Documents\OpenLearningSolutions08-01-2013\OpenLearningSolutions\purchase.aspx.cs 70  21  C:\...\OpenLearningSolutions\

here is my code:

OLSContainer ols = new OLSContainer();
        var reSet = from l in ols.LEVEL_COURSE
                    join lp in ols.PACKAGES 
                    on new { l.course_ID, l.levelID } equals new { lp.course_ID, lp.level_ID }
                    select l;

although all the four columns are of type int nullabe but i am getting this error. Kindly help me.

3 Answers 3

1

In your LINQ expression, the names of the members are different so the types end up being different so C# cannot figure out the common type between the two.

Try this.

OLSContainer ols = new OLSContainer();
var reSet = from l in ols.LEVEL_COURSE
                join lp in ols.PACKAGES 
                on new { l.course_ID, l.levelID } equals new { course_ID = lp.course_ID, levelID = lp.level_ID }
                select l;
1
  • It's the member names from the left side in join expression Jan 11, 2013 at 8:31
1

I solved my problem by selecting data from tables this way:

OLSContainer ols = new OLSContainer();
        var reSet = (from l in ols.LEVEL_COURSE
                    from p in ols.PACKAGES
                    where l.course_ID == p.course_ID && l.levelID == p.level_ID &&    l.course_ID==courseID
                    select new { l.levelID, l.levelName }).Distinct();
0

If you are comparing int? and int for example, you could append .Value to the nullable property.

1
  • thanks but i solved it myself and gave the answer myself as well..:) Apr 19, 2013 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.