So is a cascading insert possible in this scenario without the commented
line:

Order order = new Order();
order.Id = GUID.NewGuid();
_orderDao.Save(order);* // Can this not be done (cascaded) by the customer
save below rather than explicitly called here?*

Customer customer = new Customer();
customer.Id = GUID.NewGuid();
customer.Orders.Add(order);
order.Customer = customer;
customerDao.Save(customer);

Like I said, it's not of huge importance but I'll not be able to sleep until
I know for sure ;)

Cheers,

Dan


2009/4/24 DannyT <[email protected]>

> So i assume it is possible then :)
>
> The mapping (generated by fluentNH)
> *Customer Class:*
>
> <?xml version="1.0" encoding="utf-8" ?>*
> *  <hibernate-mapping xmlns="*urn:nhibernate-mapping-2.2*" assembly="*Domain,
> Version=1.0.0.0, Culture=neutral, PublicKeyToken=null*" namespace="*
> MyProject.Domain*">*
>     *<class name="*Customer*" table="*`Customer`*" xmlns="*
> urn:nhibernate-mapping-2.2*">*
>     *<id name="*Id*" type="*Guid*" column="*Id*">
>         <generator class="*assigned*" />
>     </id>*
>     *<property name="*Name*" type="*String*">
>         <column name="*Name*" />
>     </property>
>     ** <bag name="*Orders*" cascade="*all*" inverse="*true*">
>         <key column="*Customer_id*" />
>         <one-to-many class="*MyProject**.Domain.Order, Domain,
> Version=1.0.0.0, Culture=neutral, PublicKeyToken=null*" />
>     </bag>
> </class>
> </hibernate-mapping>
>
> *Order Class*
>
>   <?xml version="1.0" encoding="utf-8" ?>*
>     *<hibernate-mapping xmlns="*urn:nhibernate-mapping-2.2*" 
> assembly="*Domain,
> Version=1.0.0.0, Culture=neutral, PublicKeyToken=null*" namespace="*
> MyProject**.Domain*">*
>     *<class name="*Order*" table="*`Order`*" xmlns="*
> urn:nhibernate-mapping-2.2*">*
>     *<id name="*Id*" type="*Guid*" column="*Id*">
>         <generator class="*assigned*" />
>     </id>
>     <many-to-one cascade="*none*" name="*Customer*" column="*Customer_id*"
> />*
> *    <property name="*Quantity*" type="*Int64*">
>         <column name="*Quantity*" />
>     </property>**
> </class>
> </hibernate-mapping>
>
> This Works:
>
> Order order = new Order();
> order.Id = GUID.NewGuid();
> _orderDao.Save(order);* // fails without this line*
>
> Customer customer = new Customer();
> customer.Id = GUID.NewGuid();
> customer.Orders.Add(order);
> order.Customer = customer;
> customerDao.Save(customer);
>
> This isn't a huge problem but would like to know the problem
>
>
>
> 2009/4/24 Fabio Maulo <[email protected]>
>
> and the mapping is ?
>>
>> 2009/4/24 DannyT <[email protected]>
>>
>> Is it possible to cascade an insert on a one to many bidirectional using
>>> assigned IDs when the FK of the child has a constraint?
>>>
>>> E.g.
>>>
>>> Customer customer = new Customer();
>>> customer.Id = 1;
>>> Address address = new Address();
>>> address.Id = 1;
>>> customer.Addresses.Add(address);
>>> customerDao.SaveOrUpdate(customer); // want this to insert the customer
>>> then insert the address using the assigned customer ID
>>>
>>> I want to see this just perform 2 plain inserts with no updates to apply
>>> the foreign key as that's currently violating fk constraints.
>>> I've set cascade="all" and inverse="true" on the address collection.
>>>
>>> Currently we're getting an NHibernate first chance stale state exception?
>>>
>>> If it's technically possible I'll send more details but just want to
>>> check if it's even technically possible.
>>>
>>> Cheers,
>>>
>>> Dan
>>>
>>>
>>>
>>
>>
>> --
>> Fabio Maulo
>>
>> >>
>>
>
>
> --
> http://danny-t.co.uk
>



-- 
http://danny-t.co.uk

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