Nhibernate QueryOver 我怎样才能让这个查询使用异步?

Nhibernate QueryOver how can I make this query use async?

对于这个新网站,我想在 NHibernate 中使用异步方法。我有一个使用 QueryOver API 的简单查询,但我无法让它与异步一起工作。

这是一个简单的查询,其中包含一些列出所有企业的 where 子句。我每次执行此操作时都想要其中的 20 个。

查询:

BusinessListItem bli = null;
BusinessCategory bc = null;
Category c = null;
BusinessImage bi = null;
Image i = null;

var q = Session.QueryOver<Business>()
            .JoinAlias(x => x.Categories, () => bc)
            .JoinAlias(() => bc.Category, () => c)
            .JoinAlias(x => x.Images, () => bi, JoinType.LeftOuterJoin)
            .JoinAlias(() => bi.Image, () => i, JoinType.LeftOuterJoin)
            .Where(() => bc.IsMain);

        if (!string.IsNullOrEmpty(_name))
            q.WhereRestrictionOn(x => x.Name).IsLike($"%{_name}%");

        if (!string.IsNullOrEmpty(_streetName))
            q.WhereRestrictionOn(x => x.StreetName).IsLike($"%{_streetName}%");

        if (_categoryId != null)
            q.Where(() => c.Id == _categoryId.Value);

        if (_subCategoryIds != null)
            q.WhereRestrictionOn(() => c.Id).IsIn(_subCategoryIds);

        return q.Select(
                Projections.Property<Business>(x => x.Id).WithAlias(() => bli.Id),
                Projections.Property<Business>(x => x.Name).WithAlias(() => bli.Name),
                Projections.Property("c.Name").WithAlias(() => bli.CategoryName),
                Projections.Property("bi.Image").WithAlias(() => bli.Image)
            )
            .TransformUsing(Transformers.AliasToBean<BusinessListItem>())
            .List<BusinessListItem>()
            .OrderBy(x => x.Name)
            .Skip(_skipCount)
            .Take(20)
            .ToList();

我知道 .ListAsync() 方法存在,但我无法让它与 Skip、Take 和 OrderBy 方法一起使用。

非常感谢任何帮助!

这道题的答案是:

var result = await q.Select(
                Projections.Distinct(
                    Projections.Property<Business>(x => x.Id).WithAlias(() => bli.Id)
            )
            .TransformUsing(Transformers.AliasToBean<BusinessListItem>())
            .OrderBy(x => x.Name).Asc
            .Skip(_skipCount)
            .Take(_takeCount)
            .ListAsync<BusinessListItem>();

        return result.ToList();

感谢@DavidOsborne