I have the following scenario, a Customer who can have bank accounts in several Banks. This relation is described as an IDictionary in the Customer class (mapped using the map tag):
public class Customer
{
public virtual IDictionary<Bank, string> Banks
{
get { return _Banks; }
set { _Banks = value; }
}
private IDictionary<Bank, string> _Banks = new Dictionary<Bank, string>();
}
Each key in the IDictionary represents a Bank where the Customer has an account, and the string value is a simple status not relevant for this question.
What I would like to do is a NHibernate query to retrieve all Customers that have an account in a specified Bank. I tried this inside the Bank class (hence the this keyword is referring to a Bank):
IList<Customer> customers = session.QueryOver<Customer>()
.Where(x => x.Banks.Keys.Contains(this))
.List();
And even thought the above query compiles without errors when I try to run it I get the following exception:
System.Exception: Unrecognised method call: System.Collections.Generic.ICollection`1[[Finance.Bank, Finance, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]:Boolean Contains(Finance.Bank)
So how can I correctly perform this kind of query? Thanks!
PS: This SO question shows how to do it for an ISet collection, and this SO question states that what I'm attempting may not be possible using the ICriteria API.