我有以下Linq,我认为它在语法上是正确的。
var result = from t1 in context.t1
join t2 in context.t2
on new { t1.field1, t1.field2 } equals new { t2.field1, t2.field2 }
select new { t1, t2 };
但是我收到以下错误:
CS1941 The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'Join'.
在检查数据库时,我发现了以下内容:
table1 | table2
|
field1 varchar(16) | field1 varchar(50)
field2 varchar(30) | field2 varchar(50)
字段数据类型和长度是否匹配?
答案 0 :(得分:1)
Can you please try this .
var result = from x in entity
join y in entity2
on new { X1= x.field1, X2= x.field2 } equals new { X1=y.field1, X2= y.field2 }
select new
{
/// Columns
};