我有以下情况。我有Customer
和CompanyCustomerAssignment
对象(具有 1:1 的关系)。中的属性之一CompanyCustomerAssignment
是CustomerGroup
。现在 - 我想QueryOver
- 何时CustomerGroup
通过,而不是 fetchCustomers
属于该组,但是当它为 null 时,我想查询所有。好吧,在“SQL”中看起来很简单:
...WHERE CustomerGroupId = @param OR @param is NULL;
不幸的是,我不知道 QueryOver (custGrp
是参数 - 可以是对象或null
)
Customer c = null;
CompanyCustomerAssignment cca = null;
_session.QueryOver<Customer>(() => c)
.JoinAlias(() => c.CompanyCustomerAssignment, () => cca)
.Where(() => cca.Company == currentCompany && c.IsActive == true)
.And(() => cca.CustomerGroup == custGrp || custGrp == null ) // <- this seems to be problem to me
.List()
.Select(x => new CustomerApiModel() {CustomerId = x.Id})
.ToList();
但这不起作用 - 我收到一条消息,它Customer
没有这样的属性,这听起来合乎逻辑,但对我毫无帮助。