我有一个如下的autoquery实现:
public QueryResponse<BlogDto> Get(BlogsLookUpRequest request)
{
AutoMapping.RegisterConverter((Blog from) => {
var to = from.ConvertTo<BlogDto>(skipConverters: true); // avoid infinite recursion
to.Category = string.Join(",", from.BlogToBlogCategories.Select(x => x.BlogCategoryId.ToString()).Distinct());
return to;
});
var q = _AutoQuery.CreateQuery(request, base.Request);
var results = _AutoQuery.Execute(request, q);
return results;
}
我的自动查询类型是
QueryDb<Blog, BlogDto>
.
如果没有,最好的方法是什么来改变结果?
我通过声明另一种类型来实现
public class BlogEntityQuery : QueryDb<Blog>
那没有路线。然后这样做了:
public QueryResponse<BlogDto> Get(BlogsLookUpRequest request)
{
AutoMapping.RegisterConverter((Blog from) => {
var to = from.ConvertTo<BlogDto>(skipConverters: true); // avoid infinite recursion
to.Category = string.Join(",", from.BlogToBlogCategories.Select(x => x.BlogCategoryId.ToString()).Distinct());
return to;
});
var q = _AutoQuery.CreateQuery(request, base.Request);
var rawResults = _AutoQuery.Execute(new BlogEntityQuery().PopulateWith(request), q);
var results = new QueryResponse<BlogDto>().PopulateWith(rawResults);
return results;
}
它很管用,但感觉有点老土。由于AutoQuery正在执行自动映射,我觉得应该有一个选项来注册一个转换器供它使用。