locked
join clause is incorrect. Type inference failed in the call to 'Join error RRS feed

  • Question

  • User-436309264 posted

    Hello Everyone,

    I am trying to join tables with Multiple conditions and getting error "join clause is incorrect. Type inference failed in the call to 'Join error". 

    Getting the error at   join c in db.Counties on new {i.CountyCode_I4,i.StateCode_I3}  equals new {c.CountyCode,c.StateCode}

    Unable to find the cause . Please guide

    Thanks

    Kapil 

    var query = from i in db.InventoryItems
    join s in db.States on i.StateCode_I3 equals s.StateCode
    join c in db.Counties on new {i.CountyCode_I4,i.StateCode_I3} equals new {c.CountyCode,c.StateCode}
    select new InventoryItemStateAndCounty
    {

    OwnerCode = i.Owner_C1.ToString(),
    TunnelNo = i.TunnelNo_I1,
    TunnelName = i.TunnelName_I2,
    StateCode = i.StateCode_I3.ToString(),
    StateName = s.StateName,
    CountyCode = i.CountyCode_I4.ToString(),
    CountyName = c.CountyName,
    Year = i.Year.ToString(),
    SubmitBy = i.SubmitBy.ToString(),
    FedAgency = i.FedAgency,
    PlaceCode = i.PlaceCode_I5.ToString(),
    RouteNumber = i.RouteNumber_I7,
    FacilityCarried = i.FacilityCarried_I10,

    Monday, October 26, 2015 1:14 PM

Answers

  • User-271186128 posted

    Hi Kapils573,

    I am trying to join tables with Multiple conditions and getting error "join clause is incorrect. Type inference failed in the call to 'Join error". 

    Getting the error at   join c in db.Counties on new {i.CountyCode_I4,i.StateCode_I3}  equals new {c.CountyCode,c.StateCode}

    As for this issue, I suggest you could check the data type, and make sure they have the same data type.

    Besides, I suggest you could try to modify your code as below:

    var query = from i in db.InventoryItems
     join s in db.States on i.StateCode_I3 equals s.StateCode
     join c in db.Counties on new {CountyCode = i.CountyCode_I4, StateCode = i.StateCode_I3} equals new {CountyCode  = c.CountyCode,StateCode = c.StateCode}
     select new InventoryItemStateAndCounty
     {
    
     OwnerCode = i.Owner_C1.ToString(),
     TunnelNo = i.TunnelNo_I1,
     TunnelName = i.TunnelName_I2,
     StateCode = i.StateCode_I3.ToString(),
     StateName = s.StateName,
     CountyCode = i.CountyCode_I4.ToString(),
     CountyName = c.CountyName,
     Year = i.Year.ToString(),
     SubmitBy = i.SubmitBy.ToString(),
     FedAgency = i.FedAgency,
     PlaceCode = i.PlaceCode_I5.ToString(),
     RouteNumber = i.RouteNumber_I7,
     FacilityCarried = i.FacilityCarried_I10,

    Best regards,
    Dillion

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 26, 2015 10:32 PM