i want select values table model properties has value. model.
public class library { public ienumerable<books> books { get; set; } public string bookname { get; set; } public string color { get; set; } public int shelfnumber { get; set; } }
i want select table values equal model property filled up.
for example:
public actionresult(library lib) { var b = _bookservice.getbooks(); lib.books = b.where(x => // select values table based on properties has value in model) }
how this?
assuming properties in books
has same names properties in library
looking this:
var b = _bookservice.getbooks(); foreach (propertyinfo p in typeof(library).getproperties()) { // skip "books" property if (p.name == "books") { continue; } // skip null values lib if (p.getvalue(lib) == null) { continue; } // build condition dynamically var value = expression.constant(p.getvalue(lib)); var param = expression.parameter(typeof (books)); var predicate = expression.lambda<func<books, bool>>( expression.equal( expression.property(param, p.name), value ), param ); b = b.where(predicate); }
b
must queryable, if not change first line var b = _bookservice.getbooks().asqueryable();
Comments
Post a Comment