值相同但名称使用linq不同 [英] Values are same but names are different using linq

查看:89
本文介绍了值相同但名称使用linq不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FID中的一个表列中有两个表,db中的类型是字符串,而其他表中的列是MID,db中的类型是int bother值相同但名称不同。我尝试调整,但这显示错误



我尝试过:



there is two table in one table column in FID and type in db is string and in other table column is MID and type in db is int bother values are same but names are different . i try to adjust but this shows error

What I have tried:

string data = "[";
                var re = (from veh in DB.tblVeh
                          join regh in DB.tblRe on 
                          new{MID=veh .MID} equals new {MID=tblRe .FID}
                          where !(veh .VName == "")
                          group veh by veh .VName into g
                          select new
                          {
                              Name = g.Key,
                              cnt = g.Select(t => t.Name).Count()
                          }).ToList();


                data += re.ToList().Select(x => "['" + x.Name + "'," + x.cnt + "]")
                  .Aggregate((a, b) => a + "," + b);

                data += "]";







错误

错误2 join子句中某个表达式的类型不正确。调用加入时类型推断失败。



任何解决方案




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

any solution

推荐答案

super_user [ ^ ]写道:

一个表列是 FID 并输入db 是字符串,而在其他表格列中 MID 并输入db 是int

one table column is FID and type in db is string and in other table column is MID and type in db is int





好​​吧,错误信息与你说的完全相同。所以,你必须用以下代码替换你的陈述:



Well, error message says exactly the same as you stated. So, you have to replace your statement with:

join regh in DB.tblRe on new{MID=veh.MID} equals new {MID=(int?)regh.FID}





请看看过去的答案:

c# - 实体框架中的join子句中的一个表达式的类型不正确 - Stack Overflow [ ^ ]

C#Linq to SQL:join子句中其中一个表达式的类型是不正确的。类型推断失败 [ ^ ]


这篇关于值相同但名称使用linq不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆