Drew Ilgenfritz
Drew Ilgenfritz

Reputation: 13

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

Upvotes: 1

Views: 2309

Answers (2)

Xin
Xin

Reputation: 36600

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

Upvotes: 2

Sampath
Sampath

Reputation: 65958

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.

Upvotes: 1

Related Questions