c# - Multiple Query Conditions using Sqlite-net -
i'm developing small windows store app , i'm using sqlite-net
i got db of persons, each person has name, id, sex etc etc
in project there view search inside db. user can insert 1 or multiple information search.
so, build search object (operson) , want use reach goal.
now made function every property of person "searchbyid" "searchbyname" , on.. @ last combine functions results
is possible create unique method using power of sqlite-net, in wich concatenated?also checking of attribute's value
if pass object operson
id = null name = john age = null sex = male
is possible write query reach goal? pseudo-code
pers = (from p in db.table<persons>() (if operson.id !=null) p.id==operson.id} , {(if operson.name !=null) p.name.contains(operson.name)} , {(if condition) where-contion} select p).tolist();
i'd recommend building query in several steps. way can take conditions outside query makes cleaner , gives more control. this:
var pers = p in db.table<persons>() select p; if(operson.id !=null) pers = pers.where(p => p.id==operson.id); if(operson.name !=null) pers = pers.where(p => p.name.contains(operson.name); .... .... var results = pers.tolist();
this code still generates 1 single query executed once when call tolist()
method.
Comments
Post a Comment