views:

38

answers:

0

Hello ,

I have already read other SO posts dealing with similar but none clarified what I wanted to do.

I have MyProduct Entity and MyItem Entity. Product is made up of MyItem(s) .same like order order line scenario.

MyProduct Will need to have value objects

public class Item : EntityBase
{

    public Item()
    {
    }

    public Guid Id { get; private set; }
    public string Name { get; private set; }
    public string Description { get; private set; }

}


    public class Product
    {

        public Product()
        {

        }

        public Guid Id { get; private set; } //Edited To add This Property//    
        public string Name { get; private set; }
        public string Description { get; private set; }
        public IList<ProductComposition> ProductItems { get; private set; }

        public void AddItem(Guid ItemId, int qty)
        {

        }




    }




 public class ProductComposition : EntityBase
    {
        public Product Product { get; set; }
        public Guid ItemId { get; set; }
        public int Qty { get; set; }
        public Guid ProductId { get; set; }

        public ProductComposition(Product product, Guid itemId, int qty, Guid productId)
        {
            Product = product;
            ItemId = itemId;
            Qty = qty;
            ProductId = productId;
        }
    }

The Product Compositionis purely value and will live with Product till products life.

I was thinking of first mapping it as a one to many by treating Product Composition as a Entity for which I had to introduce the Product property in Product Composition.

Then I read about List of Components http://knol.google.com/k/fabio-maulo/nhibernate-chapter-6-collection-mapping/1nr4enxv3dpeq/9#6(2E)3(2E)(C2)(A0)Collections_of_Values_and_Many(2D)To(2D)Many_Associations (see 6.3 end just on top of 6.4) and it seems right thing to do.

what are your suggestions - continue using ProductComposition as Entity but use it as Value Item from Product Aggregate Use it as a Component (value Item) but with Product Aggregate - No ID - use Component mapping with composite key

Also, if someone can point how I can map the above using Component mapping with composite key and how Nhibernate will save the collection of component to database. I Currently use Interceptor to find if a collection item is dirty or not. Can I use the same for Component.

Let me know if further clarity is required on the question.

Thank you,

Mar