Hello,

I'm not on a deserted island but almost ....

I have 2 tables Order and OrderDetail, below the mappging file, the class...

Below the test method, in the database, I have the Order and the
OrderDetails but the property OrderDetails in Order class is null all
the time. When I try to do :
order.OrderDetails = list, I receive a message not possible to cast
IList<> to ISet.

Is there a way to do that automatically ?

You can see OrderDetailManager and others xxxxxManager I just call the
NH method in a transaction in theses method.



            using (ISession session = this._helper.GetSession())
            {
                Customer customer;
                CustomerManager customerManager = new CustomerManager(session);

                customer = customerManager.GetByCode("CUST001")[0];

                Order order = new Order();
                order.Code = new Random().Next(0, 100000).ToString();
                order.Price = 5;
                order.Customer = customer;
                order.DateAdded = DateTime.Now;
                order.Price = 65;
                new OrderManager(session).save(order);

                Product product;
                ProductManager productManager =  new ProductManager(session);
                product = productManager.GetByCode("PROD01")[0];

                IList<OrderDetail> list = new
OrderDetailManager(session).GetById(0);
                list.Add(new OrderDetail(5, 6, product,order));

                OrderDetailManager orderDetailManager = new
OrderDetailManager(session);
                orderDetailManager.save(list);
            }







    public class Order
    {
        public virtual int OrderId { get; set; }
        public virtual string Code { get; set; }
        public virtual DateTime DateAdded { get; set; }
        public virtual double Price { get; set; }

        public virtual Customer Customer { get; set; }
        public virtual User User { get; set; }
        public virtual ISet<OrderDetail> OrderDetails { get; set; }
        public virtual Invoice Invoice { get; set; }
    }

    public class OrderDetail
    {
        public virtual int OrderDetailId { get; set; }
        public virtual double Price { get; set; }
        public virtual int Quantity { get; set; }

        public virtual Order Order { get; set; }
        public virtual Product Product { get; set; }

        public OrderDetail() { }

        public OrderDetail(int qty, double price)
        {
            this.Price = price;
            this.Quantity = qty;
        }

        public OrderDetail(int qty, double price, Product product)
        {
            this.Price = price;
            this.Quantity = qty;
            this.Product = product;
        }
    }



<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="MyAssembly" namespace="MyAssembly">
  <class name="MyAssembly.Order,MyAssembly" table="`Order`">
    <id name="OrderId" column="`OrderId`"  type="Int32" unsaved-value="0">
      <generator class="native"></generator>
    </id>
    <property name="Code" column="`Code`" type="string" length="50"
not-null="false"></property>
    <property name="Price" column="`Price`" type="double"
not-null="false"></property>
    <property name="DateAdded" column="`DateAdded`" type="Date"
not-null="false"></property>

    <!-- Order / OrderDetail -->
    <set name="OrderDetails" table="`OrderDetail`" inverse="true">
      <key column="`OrderId`"/>
      <one-to-many class="MyAssembly.OrderDetail,MyAssembly"/>
    </set>
   </class>
</hibernate-mapping>


<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="MyAssembly" namespace="MyAssembly">
  <class name="MyAssembly.OrderDetail,MyAssembly" table="`OrderDetail`">
    <id name="OrderDetailId" column="`OrderDetailId`"  type="Int32"
unsaved-value="0">
      <generator class="native"></generator>
    </id>
    <property name="Price" column="`Price`" type="double"
not-null="false"></property>
    <property name="Quantity" column="`Quantity`" type="Int32"
not-null="false"></property>

    <!-- Order / OrderDetail -->
    <many-to-one name="Order" column="`OrderId`" not-null="true"
class="MyAssembly.Order,MyAssembly"/>
    <many-to-one name="Product" column="`ProductId`" not-null="true"
class="MyAssembly.Product,MyAssembly"/>
  </class>
</hibernate-mapping>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to