我試圖創建一個LINQ查詢來提取特定的子類型,它們在表中存儲爲字節。我已經嘗試過幾種變體,並且強制進入和退出字符串;但我無法獲得數字版本的工作。我認爲這是某種C#規則我不明白,但我不知道在哪裏看。有什麼建議麼?在「IN」子句中使用LINQ中的Contains - 字符串和字節不同
// This works okay, but doesn't makes sense to go in/out of string
string[] subTypes = { "2", "4" }; // 2 = Clinic, 4 = SubClinic
var clinics = from o in db.Locations
where subTypes.Contains(o.LocationType.ToString())
select o.Name;
// this version shows an error on the "where" clause
// byte[] does not contain a definition for 'Contains'...
byte[] subType = { 2, 4 }; // 2 = Clinic, 4 = SubClinic
var clinic = from o in db.Locations
where subType.Contains(o.LocationType)
select o.Name;
定義「無法獲得[它]工作」 –
什麼是財產o.LocationType的類型? – Alexei
我在EF上有點生疏,是不是'where subType.Any(x => x == o.LocationType)'工作? –