开发者

LINQ to SQL - Querying exact values

I have a query that will retrieve number > 15, although when I try and specify an exact value, for example "== "2"" I get errors

    DataClasses1DataContext db = new DataClasses1DataContext(); 
    var returnunits15 = from p in db.Products 
            where p.UnitPrice > 15 // If unit price is greater than 15...
            select p; //开发者_StackOverflow select entries

E.g. how could I adapt the query to look for an exact string e.g. "test"

and

and exact value for example 20.?


UnitPrice is decimal?
You can't compare numeric types with strings.

If you want to check for equality for numeric types, you don't need to use "" quote marks.

DataClasses1DataContext db = new DataClasses1DataContext(); 
var returnunits15 = from p in db.Products 
        where p.UnitPrice == 20
        select p;

You need to use quote marks for string comparison only.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜