我想做这个:

NHibernate.IQueryOver<DataAccess.Domain.Product, DataAccess.Domain.Product> query = session.QueryOver<DataAccess.Domain.Product>();
query = query.Where(x => x.Name == "X");
query = query.Take(1).Skip(3);
List<Product> results = query.List().ToList();

我在“跳过”或“获取”上找不到任何帮助。工具提示帮助(是的,我很拼命)说“跳过并获取”返回IQueryOver,但是错误消息却说明了“无法将IQueryOver {T}隐式转换为IQueryOver {T,T}。我不知道IQueryOver是什么{T,T}是。我无论如何都不要求其中之一。

最佳答案

尝试像这样更改您的代码:

NHibernate.IQueryOver<DataAccess.Domain.Product> query = session.QueryOver<DataAccess.Domain.Product>();
query = query.Where(x => x.Name == "X");
query = query.Take(1).Skip(3);
var results = query.List();

或者,甚至更好:
var results = session.QueryOver<DataAccess.Domain.Product>()
       .Where(x => x.Name == "X")
       .Take(1)
       .Skip(3)
       .List();

您可以检查我的代码here,下载 NHibernateQueryOver

更新:

我认为您缺少了一些东西。我建议您阅读此article,它对我真的很有帮助。
在关于关联的段落中,他们说:


IQueryOver<Cat,Kitten> catQuery =
    session.QueryOver<Cat>()
        .JoinQueryOver(c => c.Kittens)
            .Where(k => k.Name == "Tiddles");



这是我要构建多个过滤器时要做的事情:
Domain.OrderAddress addressDestination = null;
Domain.Customer customer = null;
Domain.TermsConditionsOfSale termsConditionsOfSale = null;

ICriterion filter1 = Restrictions.Where<Domain.Order>(t => t.Company == "MYCOMPANY");
ICriterion filter2 = Restrictions.Where<Domain.Order>(t => t.WareHouseDelivery == "DEPXX");
ICriterion filter3 = Restrictions.Where<Domain.Order>(t => t.Status == "X");
ICriterion filter4 = Restrictions.Where(() => addressDestination.AddressType == "99");
ICriterion filter5 = Restrictions.Where(() => addressDestination.Province.IsIn(new string[] { "AA", "BB", "CC" }));
ICriterion filter6 = Restrictions.Where(() => termsConditionsOfSale.ReturnedGoodsCode != "01");

var ordersForProvinces = session.QueryOver<Domain.Order>()
    .Inner.JoinAlias(t => t.OrderAddresses, () => addressDestination)
        .Inner.JoinAlias(t => t.Customer, () => customer)
        .Left.JoinAlias(t => t.TermsConditionsOfSale, () => termsConditionsOfSale);

ordersForProvinces
    .Where(filter1)
        .And(filter2)
        .And(filter3)
        .And(filter4)
        .And(filter5)
        .And(filter6);

var Results = ordersForProvinces.Skip(50).Take(20).List();

UPDATE-UPDATE:
NHibernate.IQueryOver<Domain.Person> person = session.QueryOver<Domain.Person>();
var myList = DoSomething(person);

方法:
private static IList<Domain.Person> DoSomething(NHibernate.IQueryOver<Domain.Person> persons)
{
    ICriterion filter1 = Restrictions.Where<Domain.Person>(t => t.CompanyName.IsLike("Customer%"));

    persons.RootCriteria.Add(filter1);
    var x = persons.Skip(1).Take(3).List();
    return (x);
}

关于nhibernate - 如何将“跳过并添加”到nHibernate IQueryOver,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6885726/

10-14 01:17