有没有办法在Ardalis中结合规范类。规范库?
我是Ardalis的新手。规范库和一般干净的体系结构。我想知道是否有一种方法可以分组多个规范类以进行可合算的查询。对于涉及大量变量的复杂查询将有助于分类并避免过度使用条件语句。
例如,我可能需要按优点或劣等分类DateTime属性,而不是添加多个条款,具体取决于客户端请求的配置,并根据请求的性质包括不同的相关实体(它们本身, ,可能会根据标准查询)。
以下示例并不能很好地说明我需要做的事情,但这可能会有所帮助。
1/根据其个人资料的完成状态获取联系列表。
public ContactByCompletion(bool IsComplete)
{
Query
.Where(prop => prop.IsComplete == IsComplete)
.OrderByDescending(ord => ord.CreatedAt);
}
2/与参数
public ContactByCreationDateSuperiorThan(DateTime dateRef)
{
Query
.Where(prop => prop.CreatedAt > dateRef.Date);
}
3/获取隶属于给定国家的联系人列表的联系人列表的列表
public ContactByCountry(string countryCode)
{
Guard.Against.NullOrEmpty(countryCode, nameof(countryCode));
Query
.Where(prop => prop.CountryCode == countryCode);
}
,因此在这个非常简单的示例中,这个想法是将这些查询组合起来,以形成一个使您接触的查询拥有一个完整的状态,该状态居住在一个给定的国家,是在有关日期之后创建的。有没有办法实现这一目标?
I am new to the Ardalis.Specification library and to the Clean Architecture in general. I was wondering if there might be a way to group multiple specification classes to make a composable query. It would be helpful for complex queries involving a large set of variables to sortBy and avoid excessive use of conditional statements.
I may need for example to sort a DateTime property either by Superior than or Inferior than, to add multiple Where clauses depending on the configuration of the request by the client and to include different related entities depending on the nature of the request (which, themselves, might be queried based on a criteria).
The following example is not a good illustration of what i need to do but that might help.
1/ Gets a list of Contact based on the state of Completion of their profile.
public ContactByCompletion(bool IsComplete)
{
Query
.Where(prop => prop.IsComplete == IsComplete)
.OrderByDescending(ord => ord.CreatedAt);
}
2/ Gets a list of Contacts with a creation Date later than the parameter
public ContactByCreationDateSuperiorThan(DateTime dateRef)
{
Query
.Where(prop => prop.CreatedAt > dateRef.Date);
}
3/ Gets a list of Contacts affiliated to a given country
public ContactByCountry(string countryCode)
{
Guard.Against.NullOrEmpty(countryCode, nameof(countryCode));
Query
.Where(prop => prop.CountryCode == countryCode);
}
So in this very simplistic example, the idea would be to combine these queries to form one that gets you the Contacts with a completed state that reside on a given country and that were created after the date in question. Is there a way to achieve that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我需要这个,所以我提出了一个解决方案。希望其他人也能利用这一点。
I needed this so I came up with a solution. Hope others also get use out of this.