I'm playing with the new code mapping feature using the Fabio Maulo
sample (http://fabiomaulo.blogspot.com/2011/07/nhibernate-playing-with-
mapping-by-code.html).

I change the model to ensure that no Order can exists without a Client
(just the relevant code):

    public class OrderMapping : EntityMapping<Order>
    {
        public OrderMapping()
        {
            ManyToOne(x => x.Customer, map =>
                {
                    map.NotNullable(true); // <<<<< CHANGE HERE
                    map.Column("CustomerId");
                });
            Property(x => x.EmissionDay, map =>
map.Type(NHibernateUtil.Date));
            Bag(x => x.Items, map => map.Key(km =>
km.Column("OrderId")));
        }
    }

    public class CustomerMapping : EntityMapping<Customer>
    {
        public CustomerMapping()
        {
            Property(x => x.CommercialName);
            NaturalId(map => map.Property(x => x.TaxId));
            Bag(x => x.Orders, map =>
                {
                    map.Key(km => km.Column("CustomerId"));
 
map.Cascade(Cascade.All.Include(Cascade.DeleteOrphans));
                });
        }
    }

When I try delete a Client instance with some Orders I receive this
exception:
{"could not delete collection: [ConsoleApplication2.Customer.Orders#1]
[SQL: UPDATE [Order] SET CustomerId = null WHERE CustomerId = @p0]"}

Why NHibernate try to set Order.CustomerId = null before delete the
record? Is there a way to workaround this behavior?

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