mardi 26 juillet 2016

If statement in LINQ where clause C#

I have written a query, and was wondering how I could implement an if statement in the where clause so that the "category_id" filter can only be added if the value is set. If the "category_id" value is null, then it would not complete the statement. Basically I am trying to make this statement into a toggle when inputting through SQL

var r = from lh in db.lh_url
        where lh.category_id == clientInfo.cf.category_id
        where lh.first_id >= id
        where lh.first_id < (id + BatchSize)
        orderby ph.url, ph.vendor, ph.product
        select new
        {
            lh
        };

Aucun commentaire:

Enregistrer un commentaire