LINQ to SQL使用=>不允许对String操作 [英] LINQ to SQL use of => operand on String not allowed
问题描述
Possible Duplicate:
string1 >= string2 not implemented in Linq to SQL, any workarround?
要简要说明我要实现的目标,我们有一个名为Application的表,它存储应用程序的版本号.例如,该表的内容是
To give a brief summary of what I want to achieve we have a table called Application and it stores application version numbers. The contents of that Table for example is
ApplicationID VersionID
1 R1.01.01.01
2 C8.00.00.01
2 C8.00.00.02
2 R8.10.00.00
2 R8.20.00.02
2 R9.00.00.01
2 R9.00.00.02
2 R9.00.00.03
3 R7.00.30.00
当我在TSQL中执行此查询时,没有任何问题,并且得到了正确的结果(请注意,VersionID是nvarchar类型)
When I am doing this query in TSQL, there are no problems and I get the correct results (Take note that the VersionID is nvarchar type)
Select * From Applications where VersionID >= 'R9.00.00.01' and ApplicationID = 2
但是当我像这样开始使用LINQ to SQL
but when I start using LINQ to SQL like such
var Applications = from v in db.Applications
where v.VersionID.StartsWith("R")
&& v.VersionID >= "R9.00.00.01"
&& v.ApplicationID == 2
orderby v.VersionID
select v;
然后我得到一个错误:运算符> =不能应用于类型为'string'和'string'的操作数
Then I get the error "Operator >= cannot be applied to operands of type 'string' and 'string'
我如何在LINQ to SQL中实现这一点而不更改数据库端的任何内容?
How do I achive that in LINQ to SQL without changing anything on the database side?
推荐答案
使用 string.Compare()
?
&& string.Compare( v.VersionID , "R9.00.00.01" ) >= 0
这篇关于LINQ to SQL使用=>不允许对String操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!