【发布时间】:2015-12-16 21:47:02
【问题描述】:
我正在尝试创建一个 LINQ 查询来提取特定的子类型,这些子类型在表中存储为字节。我尝试了几种变体,并让它强制进出字符串;但我无法使用数字版本。我认为这是我无法正确理解的某种 c# 规则,但我不确定在哪里看。有什么建议吗?
// 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;
【问题讨论】:
-
定义“无法 [it] 工作”
-
属性o.LocationType的类型是什么?
-
我的 EF 有点生疏了,
where subType.Any(x=> x == o.LocationType)有用吗? -
Entity Framework 用 byte[] 做了一些有趣的事情:lehmamic.wordpress.com/2012/08/14/…
-
o.LocationType 被定义为 tinyint,我假设它与 byte 相同;他们不是所以我需要说 subType.Contains(byte)o.LocationType)