[英]Query with linq using a where clause
Okay so I've already asked this question but I've narrowed it down and am now able to word it better. 好的,所以我已经问过这个问题,但我已经把它缩小了,我现在能够更好地说出来了。
I have a sql database and an asp.net mvc project with entity frameworks. 我有一个sql数据库和一个带有实体框架的asp.net mvc项目。 I already figured out how to query the database and display all contents. 我已经想出了如何查询数据库并显示所有内容。 But now I need to query the database and only display the rows where column "a" is greater than or equal to column "b". 但现在我需要查询数据库,只显示列“a”大于或等于列“b”的行。
Edit: datatypes in both columns are int 编辑:两列中的数据类型都是int
Here is the query I need 这是我需要的查询
Select *
from Inventory
Where quantity <= statusLow
var context = new MyContext();
var query = context.Inventory.Where(p=> p.quantity <= p.statusLow); // write the statement to query
var result = query.ToList(); // obtaining the result, trigger the database
You can try as shown below. 您可以尝试如下所示。
using (var db = new yourContext())
{
var result = db.Inventory.Where(a=> a.quantity <= a.statusLow).ToList();
}
You can learn more about LINQ to Entities here. 您可以在此处了解有关LINQ to Entities的更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.