NHibernate IQueryable collection as property of root

前端 未结 3 1367
时光说笑
时光说笑 2021-02-13 12:15

I have a root object that has a property that is a collection.

For example:

I have a Shelf object that has Books.

// Now
public class Shelf 
{
    publ         


        
3条回答
  •  孤独总比滥情好
    2021-02-13 12:50

    I tend to think like this:

    Aggregate roots are boundaries of consistency, so if shelf needs to enforce some sort of consistency policies on the books it contains, then it should be an aggregate root. And in such case it should hold a set/collection of books.

    If you don't need to enforce consistency in any way from shelf to books, then I'd consider to remove the set/collection property and move those queries into a repository instead.

    Also, since pagination and filtering most likely don't have anything to do with your domain logic, it is most likely for presentation. Then I'd consider to make some special view for it instead of adding presentation facillities to my repositories.

    e.g.

    var result = Queries.FindBooksByShelf(shelfId,pageSize);
    

    Such query could return projections and/or be optimized as plain SQL etc. They are most likely specific for a certain view or report in your GUI. This way your domain will focus on domain concepts only.

提交回复
热议问题