c# - Create dynamic Linq queries for XML -
i want build query builder user has opportunity input different conditions "id > 10" "and id < 40".
also user can select different xml elements wants display. example can select display id element , code element.
i have 2 lists 1 filters user selects , 1 elements wants show. problem don't know how add logical operator "&&" , "||" linq clause.
also not know how dynamically generate select statement include fields user selected.
here have far :
xdocument doc = xdocument.load(xmlfile); var query = doc.descendants("student"); // iterate through conditions , add them linq query foreach(whereconditions wcon in whereconditions) { query = query.where(x => (int)x.element(wcon.selectedfield) > int32.parse(wcon.comparisonvalue)); } foreach(string selectedcolumns in selectedfields) { xelement x; x = doc.root.element("students").element("student"); query = query.select(x =>(new {selectedcolumns = x.element(selectedcolumns).value})); }
Comments
Post a Comment