NHibernate QueryOver存在的地方

时间:2012-04-12 11:51:59

标签: nhibernate fluent-nhibernate queryover

CUSTOMER,COMPANY和关系表CUSTOMER_COMPANY,它保持公司和客户之间的关系。

我有一个电子邮件列表

列出emailList

我想搜索属于特定公司的客户,并且他/她的电子邮件(这是一个字段)位于此电子邮件列表中。如何使用QueryOver?

public class CustomerMap : ClassMap<Customer>
{
    public CustomerMap()
    {
        Id(x => x.Id);
        Map(x => x.Name);
        Map(x => x.Email);
        //... Other Fields

        HasMany(x => x.CompanyCustomers);
    }
}


public class CompanyMap : ClassMap<Company>
{
    public CompanyMap()
    {
        Id(x => x.Id);
        Map(x => x.Title);
            //... Other Fields

        HasMany(x => x.CompanyCustomers);
    }
}


public class CompanyCustomerMap : ClassMap<CompanyCustomer>
{
    public CompanyCustomerMap()
    {
        Id(x => x.Id);
        Map(x => x.IsActive);
        Map(x => x.CustomerType);
        ...

        References(x => x.Customer);
        References(x => x.Company);
    }
}

我希望获得属于电子邮件列表中存在的公司的客户...

1 个答案:

答案 0 :(得分:1)

您可以尝试这样:

Company company = null;
session.QueryOver<Customer>
  .JoinAlias(customer => customer.Company, () => company)
  .WhereRestrictionOn(() => company.Email).IsIn(new[] { "email_1", "email_2", ... })
  .TransformUsing(Transformers.DistinctRootEntity)
  .List();