开发者

List Database Entries According to Condition MVC 3

开发者 https://www.devze.com 2023-04-03 04:20 出处:网络
I am developing an MVC 3 application in C# and I would like to know how to list database entries, based on a condition. In my case, I only want to display invoices that have the status \"Paid\" or \"P

I am developing an MVC 3 application in C# and I would like to know how to list database entries, based on a condition. In my case, I only want to display invoices that have the status "Paid" or "Partly Paid".

So this is where I list them:

    public ViewResult Index()
    {

        var invoices = db.In开发者_开发知识库voice.Include(c => c.Client);
        return View(db.Invoice.ToList());
    }

How I would I add the condition into this code?

Thanks, Amy


Try this:

public ViewResult Index()
{

    var invoices = db.Invoice.Include(c => c.Client).Where(i => i.Status !="Confirmed";
    return View(invoices.ToList());
}
0

精彩评论

暂无评论...
验证码 换一张
取 消