-3

I have this Code for Search.

public List<Tbl_Product> ProductSearch(DateTime startdate, DateTime enddate, string productname, int suply)
{
    var q = _db.Tbl_Product
            .Where(model => 
                model.DateReg == startdate && 
                model.DateReg == enddate)
            .Where(model => 
                model.ProductName.Contains(productname))
            .Where({});

}

Now I Need to insert this code in Last Where .

if(suply == 1)
{
    model.Suply > 0 ;
}
else
{
    model.Suply = 0;
}

How should I do it?

1

1 Answer 1

9

Personally I wouldn't do that inside the Where clause as it means you are passing the suply variable to your database.

var q = _db.Tbl_Product
    .Where(model => model.DateReg == startdate 
                 && model.DateReg == enddate
                 && model.ProductName.Contains(productname));

if(suply == 1)
{
    q = q.Where(model => model.Suply > 0);
}
else
{
    q = q.Where(model => model.Suply == 0);
}

However, if you're really adamant that you want to do it all at once:

.Where(model => (suply == 1 && model.Suply > 0)
             || (suply != 1 && model.Suply == 0));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.