Drew Ilgenfritz Drew Ilgenfritz - 1 year ago 57
ASP.NET (C#) Question

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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download