我已经查看了各种stackoverflow的答案,但我没有看到修复linq连接的方法。
2桌
var query = from tips in TblTips
where tips.Id == 30
join files in TblFiles on tips.Id equals files.Group
select new { tips, files };
错误:
Type inference failed in the call to Join
现在tips.Id是一个int而files.Group是一个varchar
我试过.Value
tips.id.Value --> the word Value not working (most recent linqpad)
(int)files.Group --> it doesn't like that ...
答案 0 :(得分:7)
问题是你不能连接不同类型的表列值!
Convert.ToInt32(column) should work in linqpad and your c# application just fine.
(我用parens包裹并添加了ToList())
如果group是string并且id是int
,这应该对你有用var query = (from tips in TblTips
where tips.Id == 30
join files in TblFiles on tips.Id equals Convert.ToInt32(files.Group)
select new { tips, files }).ToList();
<强>更新强>
每个OP,我同意他的意思,它应该将其他值转换为字符串
var query = (from tips in TblTips
where tips.Id == 30
join files in TblFiles on tips.Id.ToString() equals files.Group
select new { tips, files }).ToList();