使用where子句使用linq进行查询(Query with linq using a where clause)

编程入门 行业动态 更新时间:2024-10-28 08:29:02
使用where子句使用linq进行查询(Query with linq using a where clause)

好的,所以我已经问过这个问题,但是我已经把它缩小了,我现在能够更好地说出来了。

我有一个sql数据库和一个带有实体框架的asp.net mvc项目。 我已经想出了如何查询数据库并显示所有内容。 但现在我需要查询数据库,只显示列“a”大于或等于列“b”的行。

编辑:两列中的数据类型都是int

这是我需要的查询

Select * from Inventory Where quantity <= statusLow

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. 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".

Edit: datatypes in both columns are int

Here is the query I need

Select * from Inventory Where quantity <= statusLow

最满意答案

您可以尝试如下所示。

using (var db = new yourContext()) { var result = db.Inventory.Where(a=> a.quantity <= a.statusLow).ToList(); }

您可以在此处了解有关LINQ to Entities的更多信息。

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.

更多推荐

本文发布于:2023-07-28 18:39:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1307944.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:子句   linq   clause   Query

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!