views:

120

answers:

1

I'm writing my first NHibernate application, but I guess this question applies to any ORM framework. My application is a simple bug tracker (devs all understand the problem domain, right?), and I'm wondering how best to model the Project/Ticket relationship in the DAL. A Project has multiple Tickets; a Ticket must be owned by a Project.

Every example I've seen shows an IRepository<T>, with FindAll, Save, Delete, etc. So I have an interface IProjectRepository : IRepository<Project>.

My question comes from the following: Do I have an ITicketRepository, which knows how to talk about tickets, or is this something that the IProjectRepository needs to know about?

Or am I barking completely up the wrong tree? Can someone point me at some example code that models a parent-child relationship with a DAL?

A: 

I think you would want to put it on the IRepository repository if you are going after just the list of tickets, you could also add a Ticket collection to the Project entity and have that lazy-load the tickets. This way you could retrieve the Project from your IRepository and if you wanted all the tickets simply hit this collection, but if you are just going after just the tickets then you can work with them through the IRepository.

James Avery
But do I have two repository interfaces, or just the one? The whole IRepository<T> pattern implies I should have one per entity type.
Roger Lipscombe
I you think you should have one per entity, but that doesn't mean you can't take advantage of lazy-loading collection as well.
James Avery