簡體   English   中英

Linq查詢類型推斷在對Join的調用中失敗

[英]Linq query Type Inference failed in the call to Join

我已經查看了各種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 ... 

問題是你不能連接不同類型的表列值!

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();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM