我已经看了各种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
我试过了。价值
tips.id.Value --> the word Value not working (most recent linqpad)
(int)files.Group --> it doesn't like that ...
最佳答案
问题是不能联接不同类型的表列值!
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();