LINQ to SQL - 查询精确值
我有一个查询将检索 number > 15,尽管当我尝试指定一个确切的值时,例如“==“2””,我收到
DataClasses1DataContext db = new DataClasses1DataContext();
var returnunits15 = from p in db.Products
where p.UnitPrice > 15 // If unit price is greater than 15...
select p; // select entries
错误我如何调整查询以查找精确的字符串,例如“test”
和
精确的值(例如 20)?
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; // 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.?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
UnitPrice
是十进制吗?不能将数字类型与字符串进行比较。
如果要检查数字类型是否相等,则不需要使用“”引号。
仅需要使用引号进行字符串比较。
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.
You need to use quote marks for string comparison only.