Hi, I'm developing an ASP.Net 2.0 app for a medium trust server using 1.2. The example app in the src and posts on this forum really helped me get a prototype working. Thanks!!!!
Now I'm struggling with some design questions since medium trust forces me to set lazy=”false” on all my classes. I have a lot of relationships and entities in my design. I don’t think I can live with eager fetching of everything. How do I design the mappings and classes so that I control how much data is fetched?
Say I have a class called Company with 3 bi-directional associations to other classes called Employee, Building, and Vendor. I’m assuming if I retrieve an Employee with lazy=”false” that NHibernate will retrieve not only Employee but also Company, Building, and Vendor along with all the classes they are associated with in a recursive fashion until the whole graph ends up in memory. Is this assumption correct?
I’ve thought of these approaches and would like your feedback and ideas:
1) I read somewhere that it might be possible to get lazy=”true” to work in medium trust if I implement an interface that NHibernate uses to create proxies for my classes instead of using DynamicProxy. I like this approach but I can’t find any information on how to replace DynamicProxy.
2) Don’t map collections. Instead add enough logic to classes so that they lazy load and build collections as needed. I think I’d loose the ability to use all but the simplest HQL statements. I’d also have to implement logic for saving objects in the correct order.
I use native id’s so perhaps this approach also helps get around the problem of not being able to use <idbag>’s to improve update performance.
3) Determine classes that the application typically uses together and map the collections between them. Use approach #2 at the boundary between groups for less traveled associations.
4) I don’t know if this would work correctly due to NHibernate caches and proxy creation, but create a base class for an entity then implement associations I use together in derived classes. Map the derived classes along with associations and use NHibernate to work with the particular derived class that implements the associations I need for the task at hand. Each derived class would only have a subset of the associations so eager fetching is reduced.
Any help is appreciated,
Thanks…
|