none
Type inference error on join RRS feed

  • Question

  • Hi, I have the following query which runs perfectly:

    1 from t in TableA  
    2 join z in   
    3 (  
    4 from ts in TableA  
    5 group ts by ts.BadgeId  
    6 into g  
    7 join b in TableB on g.Key equals b.Id  
    8 select new {   
    9             BadgeId = g.Key,   
    10             MostRecent = g.Max(ts => ts.CreatedDate),             
    11             }  
    12 )  
    13 on new { t.BadgeId } equals new { z.BadgeId }  
    14 select t 

    However, I want to change line 13 to:

    on new { t.BadgeId, t.CreatedDate } equals new { z.BadgeId, z.MostRecent } 

    But now I get a type inference error in LinqPad:

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

    CreatedDate is a DateTime type, and I would have thought MostRecent would have been inferred as DateTime.

    Any ideas?

    Paul.
    Wednesday, February 25, 2009 10:27 AM

Answers

  • A little extra Googling reveals it should be:

    on new { t.BadgeId, t.CreatedDate } equals new { BadgeId = z.BadgeId, CreatedDate = z.MostRecent } 

    Thanks to Matt Warrens post here


    Paul.
    • Marked as answer by paul1664 Wednesday, February 25, 2009 12:20 PM
    Wednesday, February 25, 2009 12:20 PM