score:2

Accepted answer
 where
     (!validatestoreid || companyaddresses.companyid == storeid) 
     && (!validateactivestatus || tills.active == showenabledtills) 

score:0

var query = db.transactions.join(
    db.tills, //join to this table
    transaction => transaction.tillid //outer key
    , till => till.tillid, //inner key
    (transaction, till) => new {transaction, till}) //result of join
    .join(db.companyaddresses, //join to this table
    r => r.till.storeid, //outer key
    a => a.companyid, //inner key
    (r, address) => new {r.transaction, r.till, address}); //result of join

if(storeid != null) 
    query = query.where(d => d.address.storeid == storeid);

if(showenabledtills)
    query = query.where(d => d.till.active == true);

var items = query.select(d => new {
    d.till.tillid,
    d.till.computername,
    d.till.description,
    d.address.compdescription
    }).distinct();

score:0

public static ienumerable<t> optionalwhere<t>(this ienumerable<t> source, func<t, bool> predicate, bool excecutefilter)
{
        if (!excecutefilter)
        {
            return source;
        }
        else
        {
            return source.where(predicate);
        }
}

Related Query

More Query from same tag