2012-02-21 54 views
13

如何使这个查询像SQL一样工作?在sql中,我可以在字符串上使用<>运算符。使用大于运算符的实体框架字符串

我一直在使用Google搜索约20分钟,并且找不到解决方案。

我不能转换r.ExemptionCode为整数,因为它可能有一个像值 '91A,9AA,ZZZ,Z01'

from r in results 
where (r.ExemptionCode > "900" || r.ExemptionCode == "701" || r.ExemptionCode == "702" || r.ExemptionCode == "721" || r.ExemptionCode == "724") 
select r 

回答

24

试试这个:

from r in results 
where (r.ExemptionCode.CompareTo("900") > 0 || r.ExemptionCode == "701" || r.ExemptionCode == "702" ||  r.ExemptionCode == "721" || r.ExemptionCode == "724") 
select r 
+0

复制和粘贴直我脑。做得好。我在大量使用即时窗口后发现这一点! XD – 2012-02-21 16:51:30

+2

虽然它没有解决我的问题根据答案,你指出我在正确的方向,这是在我的案例'String.Compare(a.version,b.version,System.StringComparison.Ordinal)> 0' - 谢谢+1 – 2013-12-04 14:39:19