1

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

我有一个电子邮件列表

列出电子邮件列表

我想搜索属于特定公司的客户,并且他/她的电子邮件(这是一个字段)在此电子邮件列表中。如何使用 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);
    }
}

我想获取属于电子邮件列表中存在的公司的客户...

4

1 回答 1

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();
于 2012-04-13T09:02:47.130 回答