I am trying to configure the correct domain architecture using Fluent NHibernate and Linq for NHibernate. I have my controllers calling Repository classes that make NHibernate under the hood and pass ICollections of data. This seems to work well, as it abstracts out data access and preserves NHibernate 's small print functionality.
However, now I find situations where my controllers must use the same data calls in a different context. For example, my repo returns a list of users. This is great when I want to display a list of users, but when I want to start using child classes to display roles, etc., I run SELECT N + 1 problems. I know how to change this in NHibernate, so it uses joins instead. but my specific question is: WHERE did I put this logic? I do not want every call to GetAllUsers () to return roles either, but I need some of them.
So, here are my three options that I see:
- Change the setting in my mapping so that the roles are attached to my request.
- Create two repository calls - GetAllUsers () and GetUsersAndRoles ().
- Return the IQueryable from the repository to the controller and use the NHibernate Expand method.
Sorry if I didn’t explain it very well. I just jump into DDD and many of this terminology is still new to me. Thanks!
source share