I'm loading XML data into an object with this LINQ statement:
var smartFormFields = from smartFormField in xmlDoc.Descendants("smartFormField")
select new Models.SmartFormField
{
IdCode = smartFormField.Element("idCode").Value,
Label = smartFormField.Element("label").Value,
FieldType = smartFormField.Element("fieldType").Value,
DisplayStatus = smartFormField.Element("displayStatus").Value,
RequiredStatus = smartFormField.Element("requiredStatus").Value,
DisplayColumn = (int)smartFormField.Element("displayColumn"),
DisplayOrder = (int)smartFormField.Element("displayOrder"),
Description = smartFormField.Element("description").Value,
Example = smartFormField.Element("example").Value,
ControlType = smartFormField.Element("controlType").Value,
AutoSuggestDataSource = smartFormField.Element("autoSuggestDataSource").Value
};
However, my WHERE (and ORDERBY) statement will change each time, e.g.
it may be this:
var smartFormFields = from smartFormField in xmlDoc.Descendants("field")
where smartFormField.Element("IdCode").Value == "lastName"
select new Models.SmartFormField
{...
it may be this:
var smartFormFields = from smartFormField in xmlDoc.Descendants("field")
where (int)smartFormField.Element("DisplayOrder").Value > 50
select new Models.SmartFormField
{...
etc.
How can I put the Where statement into a variable, something like this:
PSEUDO-CODE:
string whereStatement = "where (int)smartFormField.Element(\"DisplayOrder\").Value > 50";
var smartFormFields = from smartFormField in xmlDoc.Descendants("field")
&&whereStatement
select new Models.SmartFormField
{...