The Type of One of the Expressions in the Join Clause Is Incorrect in Entity Framework

The type of one of the expressions in the join clause is incorrect in Entity Framework

The types and the names of the properties in the anonymous types must match:

new { p1 = q.QOT_SEC_ID, p2 = dpr.DPR_TS } 
equals
new { p1 = (decimal)p.PAY_SEC_ID, p2 = p.PAY_DATE }

or if p.PAY_SEC_ID were an int?:

new { p1 = (int?)q.QOT_SEC_ID, p2 = dpr.DPR_TS } 
equals
new { p1 = p.PAY_SEC_ID, p2 = p.PAY_DATE }

...which will find no matches PAY_SEC_ID is null, or

new { p1 = q.QOT_SEC_ID, p2 = dpr.DPR_TS } 
equals
new { p1 = p.PAY_SEC_ID.GetValueOrDefault(), p2 = p.PAY_DATE }

...which defaults p1 to 0 when PAY_SEC_ID is null and again no match will be found (assuming that ID values will never be 0).

The type of one of the expressions in the join clause is incorrect in Entity Framework. Constant in left join

The column names have to match in the join; here is the corrected code:

var foo = from m in db.ClientMasters
join a in db.Orders on new { ClientID = m.Id, Status = "N" } equals new { a.ClientID, a.Status } into a_join
from a in a_join.DefaultIfEmpty()
select new { ClientID = m.Id, OrderId = a.Id };

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

The types of the properties used with the equals expression must match. So for example is Table1.SomeID is Int32 and Table2.SomeID is Nullable<Int32>, then they don't match.

EDIT

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

Also check item.SomeName is same type as t2.SomeName

The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'Join'.- Linq JOIN with multiple condition

Well after a lot of trying and searching I found the solution. Thanks to @Meysam Asadi who brought a point about typecasting the anonymous types inside linq, but to add to that statement type names must also match. I found out the issue with his solution was the second property of both object (RepairLocation and StationID) are not same and that's why compiler was still throwing the same error.

I don't know why the other solutions were sugesting typecasting though. In my case it is the typecasting that was mainly causing this error.

                    join w in context.WorkOrders on iwr.WorkOrderId equals w.ID
join scr in context.StationCompanyRelations on
new { Company = w.CompanyID ?? -1, Station = w.RepairLocation ?? -1 } equals
new { Comapny = scr.CompanyID, Station= scr.StationID }

So, while writing linq to join tables with multiple condition on ON clause:-

You must match the property names and you must handle for nullable values if one propertiy from one table is nullable whilst the other one is not null.

LINQ error, 'the type of one of the expressions in the join clause is incorrect , when trying to use two joins

Apparently x.Line and z.LocationCode are incompatible types. You could change one or the other to an expression that would make both sides compatible.

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

Apart from syntax , can you check in second join expression "on new { conditionId = condition.id". Check if type "condition" is defined or not.

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

I believe you need to change the name of at least part of one of your composite keys so that they match.

See here: https://learn.microsoft.com/en-us/dotnet/csharp/linq/join-by-using-composite-keys

Something like:

on new { JobID = js.JobID, prodCode = js.ProductCode } equals new { JobID = bffd.ADFJobID, prodCode = bffd.ProductCode }

LINQ - 'the type of one of the expressions in the join clause is incorrect'

Are you sure that s.VehiculeDepot is the same type as consignments.DeliveryDepot ?

on new { Reg = s.VehicleReg, Depot = s.VehicleDepot } 
equals new { Reg = consignments.VehicleReg, Depot = consignments.DeliveryDepot }


Related Topics



Leave a reply



Submit