C#Linq-连接多字段表的问题-错误CS1941
我有以下Linq,我相信它在语法上是正确的C#Linq-连接多字段表的问题-错误CS1941,c#,entity-framework,linq,linq-to-sql,C#,Entity Framework,Linq,Linq To Sql,我有以下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
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)
字段数据类型和长度是否匹配?检查代码中的类型:
t1。field1
必须与t2.field1
的类型相同,而t2
的类型相同。链接的副本解释得更详细。
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
};