I have a linq query which i cant get working fully. The query selects from a sql server view the user is able to select a filter(on screen) from one of four radio buttons(mutually exclusive using radio list ) which are Active,New,Obsolete,Any. So it is working if i select any of Active,New,Obsolete as this value is used in query(RBstatus.SelectedValue) but i cant get linq to say if 'Any' is selected miss the filter and just output every thing. The complete query is
var query = (from b in context.mpcViewFormulas.Where(X =>
X.FormulaCode.Contains(formualcode)
&& X.BaseCode.Contains(txtBase.Text)
&& X.Status.Contains(RBstatus.SelectedValue))
what i want to do is if 'Any' radio button is selected then miss the last && off the query (&& X.Status.Contains(RBstatus.SelectedValue) or is this the wrong way to go?
What i have tried is
var query = (from b in context.mpcViewFormulas.Where(X =>
X.FormulaCode.Contains(formualcode)
&& X.BaseCode.Contains(txtBase.Text)
if(RBstatus.SelectedValue !="Any")
{
&& X.Status.Contains(RBstatus.SelectedValue)
})
this throws error query body must end with a select cluse or a group clause and invalid expression trem &&
Aucun commentaire:
Enregistrer un commentaire