PETA POCO在其中[英] Peta Poco where clause

本文是小编为大家收集整理的关于PETA POCO在其中的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我试图在petapoco

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

问题在于它从数据库中获取整个记录集,然后在其上执行过滤.我尝试获取而不是查询,结果相同.

如何编写查询,以便它发送查询以获取数据库的过滤结果,而不是在WebServer上进行过滤?

推荐答案

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

或使用npoco(基于petapoco的)这也可能

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

本文地址:https://www.itbaoku.cn/post/1557099.html

问题描述

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?

推荐答案

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");