The type arguments cannot be inferred from the query in linq c# query

Below is my piece of linq code

mTimeslot = (from users in mContext.MFUsers
             join tblTime in mContext.tblTimeslots on users.UserID equals tblTime.varAdvisorId
             join tblApp in mContext.tblAppointments on new { varAdvisorId=users.UserID,tblTime.varSlotId} equals new {tblApp.varAdvisorId, varSlotId = tblApp.varSlotId}
             select new Timeslot
             {
                 varAdvisorId = users.UserID,
                 varAdvisorName = users.varUserName
             }).FirstOrDefault();

In the second join I'm getting an error saying the type argument cannot be inferred from the query.

tblTime.varSlotId is an integer while tblApp.varSlotId is a nullable integer. I can figure out that the error is in the above mentioned column. But I'm unable to convert the integer value to a nullable integer as both the columns have the name of varSlotId.

Jon Skeet
people
quotationmark

tblTime.varSlotId is an integer where tblApp.varSlotId is a nullable integer.

Well that's the problem then. Your two anonymous types aren't the same, and they need to be. It's probably simplest just to cast tblTime.varSlotId:

join tblApp in mContext.tblAppointments
    on new { varAdvisorId = users.UserID, varSlotId = (int?) tblTime.varSlotId }
    equals new { tblApp.varAdvisorId, tblApp.varSlotId }

people

See more on this question at Stackoverflow