ServiceStack ORMLite-如何全选以自动匹配请求DTO的属性 [英] ServiceStack ORMLite - How to Select All to match the request DTO's properties automatically
问题描述
我有几个ServiceStack ORMLite POCO,其中一个是下面的Company。
I have several ServiceStack ORMLite POCO, one is Company below.
public class Company
{
[AutoIncrement]
public int id { get; set; }
public string company { get; set; }
public int? companyNo { get; set; }
public bool? active { get; set; }
}
如果以下请求中的两个属性有效:req.company = ABC Company,req.active = ture和所有其他属性为空。然后,它可以返回匹配两个属性的所有记录。代码可能如下所示:
If two properties are valid in the following request: req.company="ABC Company", req.active=ture, and all other properties are null. Then it can return all records matching the two properties. The code may look like below:
public object Get(Company req)
{
return Db.Select<Company>().Where<Company>(req);
}
ServiceStack ORMLite是否具有这样的WHRER来自动匹配请求DTO?
Does ServiceStack ORMLite have such a WHRER to auto-match the valid properties in the request DTO?
推荐答案
这不是OrmLite的功能,但可以在自动查询,您只需要定义要查询的请求DTO,例如:
This is not a feature in OrmLite, but it's available in AutoQuery where you just need to define the Request DTO you want to query, e.g:
[Route("/company/search")]
public class QueryCompany : IQuery<Company>
{
public int Id { get; set; }
public string Company { get; set; }
public int? CompanyNo { get; set; }
public bool? Active { get; set; }
}
仅使用Request DTO,ServiceStack会自动为您创建服务可以像其他任何服务一样进行查询。
With just the Request DTO, ServiceStack automatically creates the Service for you which you can query like any other Service.
您可以通过注册自动查询功能来启用自动查询,例如:
You can enable AutoQuery by registering the AutoQuery Feature, e.g:
Plugins.Add(new AutoQueryFeature { MaxLimit = 100 });
自动查询位于 ServiceStack.Server NuGet程序包:
AutoQuery is available in the ServiceStack.Server NuGet package:
PM> Install-Package ServiceStack.Server
这篇关于ServiceStack ORMLite-如何全选以自动匹配请求DTO的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!