开发者

LINQ to SQL use of => operand on String not allowed [duplicate]

This question already has answers here: Closed 12 years ago.

Possible Duplicate:

string1 >= string2 not implemented in Linq to SQL, any workarround?

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  开发者_如何学C                    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

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

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;

Then I get the error "Operator >= cannot be applied to operands of type 'string' and 'string'

How do I achive that in LINQ to SQL without changing anything on the database side?


use string.Compare()?

&& string.Compare( v.VersionID , "R9.00.00.01"  ) >= 0


use

string.Compare(v.VersionID, "R9.00.00.01") >= 0

instead

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜