looks like you're managing sessions in a peculiar way

On Tue, Mar 24, 2009 at 9:26 AM, Kris-I <[email protected]> wrote:

> Hello,
>
> I have some trouble with something simple .... in theory.
>
> I have an Order table and an Invoice table with a relation between. The
> Invoice can be the invoice for several Order (even if it's not the case a
> this time may be later).
>
> I use exactly the same strategy than Order and OrderDetail, when I change
> an Order, the OrderDetail are updated too.
>
> With the Order/Invoice that's not work and I don't understand why
>
>
> The Order class :
>     public class Order
>     {
>         public virtual int OrderId { get; set; }
>         public virtual string Code { get; set; }
>         public virtual DateTime DateAdded { get; set; }
>         public virtual DateTime DateUpdate { get; set; }
>         public virtual double Price { get; set; }
>
>         public virtual Customer Customer { get; set; }
>         public virtual ISet<OrderDetail> OrderDetails { get; set; }
>         public virtual User User { get; set; }
>         public virtual Invoice Invoice { get; set; }
>    }
>
> the mapping section with the relation
> <many-to-one name="Invoice" column="`InvoiceId`" not-null="false"
> foreign-key="FK_Invoice_Order" class="MyAssembly.Invoice,MyAssembly"/>
>
> The Invoice class :
>     public class Invoice
>     {
>         public virtual int InvoiceId { get; set; }
>         public virtual double Advance { get; set; }
>         public virtual string Code { get; set; }
>         public virtual bool IsInvoice { get; set; }
>         public virtual bool IsWithVAT { get; set; }
>         public virtual ISet<Order> Orders { get; set; }
>
>         public Invoice()
>         {
>             Orders = new HashedSet<Order>();
>         }
>
>         public virtual void AddInvoiceOrder(Order order)
>         {
>             order.Invoice = this;
>             Orders.Add(order);
>         }
>
>     }
>
> the mapping section with the relation
> <set name="Orders" table="`Order`" cascade="all-delete-orphan"
> inverse="true">
>   <key column="`InvoiceId`"/>
>   <one-to-many class="MyAssembly.Order,MyAssembly"/>
> </set>
>
> I create an instance of Invoice, I add the order like this
>  newInvoice.AddInvoiceOrder(order);
>  I use my session to save my Invoice but now I have an error : *Illegal
> attempt to associate a collection with two open sessions*
>
> If I don't do this : newInvoice.AddInvoiceOrder(order);
> I can save myInvoice but there is no relation between the Order and Invoice
> table the InvoiceId in Order table is empty.
>
> I join an image with the debug content when that's not work.
>
> Thanks,
>
>
>
>
> >
>


-- 
Ken Egozi.
http://www.kenegozi.com/blog
http://www.delver.com
http://www.musicglue.com
http://www.castleproject.org
http://www.gotfriends.co.il

--~--~---------~--~----~------------~-------~--~----~
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