开发者

Domain Modeling question / collections with NHibernate

Please consider the domain model shown below (simplified for brevity - no ids etc.) A Customer can comment on a Product only once. Lets assume (for reasons I don't want to get into here) that the Customer class cannot have a collection of Reviews that it owns. The Product is the main Aggregate root here.

Often in this situation, when retrieving the Product, it will only be in the context of a particular Customer. In other words I will only be interested in the members of the Reviews collection that belong to that particular Customer.

So, it there a way, when retrieving the Product object, of restricting the population of the collection to the review that relates to the Customer I supply? How would this be implemented in NHibernate? Is this at all consistent with NHibernate best practices (and to a lesser degree DDD)?

public class Product
{
    public virtual string Name { get; set; }
    public virtual ISet<Review> Reviews{ get; set; }

    public Product()
    {
 开发者_开发百科       Reviews= new HashedSet<Review>();
    }
}

public class Review
{
    public virtual string ReviewText { get; set; }
    public virtual Customer Reviewer { get; set; }
}

public class Customer
{
    public virtual string Name { get; set; }
}

Thanks

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜