Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

.net

linq

I have this query wit a group join:

    foreach (var item in someList)
    {
                    var result = (from t1 in someContext.Table1
                                  join t2 in someContext.Table2 on new { t1.SomeID, item.SomeName} equals new {t2.SomeID, t2.SomeName} into j1 
                                  ...
    }

I would like to know if it is possible to have a group join as above?

new { t1.SomeID, item.SomeName} equals new {t2.SomeID, t2.SomeName}

item.SomeName comes from the list i am iterating through.

If not, how would i change the statement to get the desired results?

like image 578
Willem Avatar asked Apr 13 '12 08:04

Willem


1 Answers

In this case you must be sure that the properties and type of the two new anonymous objects are the same. I usually give specific name of properties.

Ex.:

 var result = from t1 in someContext.Table1
              join t2 in someContext.Table2 on 
                          new { SomeID = t1.SomeID, SomeName = someName} equals 
                          new { SomeID = t2.SomeID, SomeName = t2.SomeName} into j1 
like image 51
Hà Tây Quê Rượu Avatar answered Sep 28 '22 07:09

Hà Tây Quê Rượu