Peta Poco where clause

余生颓废 提交于 2019-12-24 14:15:33

问题


I am trying to do this in petapoco

var people 
= db.Query<Person>("SELECT * FROM people").Where(p => 
 p.FirstName.Equals("George") && p.LastName.Equals("Clooney")).ToList();

the problem is that it gets the entire set of records from the database and then performs the filtration on it. I tried Fetch instead of query, same result.

How do I write the query so that it sends the query to get the filtered results from the database, instead of doing the filtering at the webserver?


回答1:


var people = db.Fetch<Person>("where firstname = @0 and lastname = @1", 
    "George", "Clooney");

or using NPoco (which which is based off PetaPoco) this is also possible

var people = db.FetchWhere<Person>(x=>x.FirstName == "George"
    && x.LastName == "Clooney");


来源:https://stackoverflow.com/questions/18391875/peta-poco-where-clause

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!