I have three tables, Group -> User -> Account.
Group can have multiple users and user can have multiple accounts.
when i try to fetch all the accounts in the group with query
var accounts = accountRepository.FindAll(x => x.User.Group.Id == groupId);
where FindAll is method in common repository
/// <summary>
/// Find all entities with filter
/// </summary>
/// <param name="expression">Linq expression</param>
/// <returns>IQueryOver of entity of type TEntity</returns>
public IQueryOver<TEntity> FindAll(Expression<Func<TEntity, bool>> expression)
{
var query = _session.QueryOver<TEntity>();
query.Cacheable().CacheMode(CacheMode.Normal);
return query.Where(expression);
}
my query to find all the accounts in Groups does not work as it throw error with message
could not resolve property: User.Group.Id
Whats the better way to write this query in
Use Linq to NHibernate instead:
Unlike
QueryOver, the Linq provider supports these kind of queries (traversing through the entity hierarchy), turning it into SQL joins.