Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#Linq-连接多字段表的问题-错误CS1941_C#_Entity Framework_Linq_Linq To Sql - Fatal编程技术网

C#Linq-连接多字段表的问题-错误CS1941

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

我有以下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)

字段数据类型和长度是否匹配?

检查代码中的类型:
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
          };