Mappings below, rowversion is suing a custom type too.
Cheers
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="A" table="A" lazy="false">
<id name="Id" column="ID" type="int">
<generator class="native" />
</id>
<version name="RowVersion" column="RowVersion" type="NHTimestamp,
Core" generated="always" unsaved-value="null" />
<property name="Name" column="Name" type="string" />
<set name="BItems" inverse="true" lazy="true" cascade="delete-
orphan">
<key column="AId" />
<one-to-many class="B" />
</set>
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="B" table="B" lazy="false">
<id name="Id" column="ID" type="int">
<generator class="native" />
</id>
<version name="RowVersion" column="RowVersion" type="NHTimestamp,
Core" generated="always" unsaved-value="null" />
<property name="Name" column="Name" type="string" />
<many-to-one name="A" column="AId" cascade="save-update" not-=""
null="true" />
</class>
</hibernate-mapping>
On Sep 14, 11:06 pm, "Fabio Maulo" <[EMAIL PROTECTED]> wrote:
> Mappings needed
>
> 2008/9/13 codemonkey <[EMAIL PROTECTED]>
>
>
>
>
>
> > Hello,
>
> > Having a slight issue and would like some solutions/suggestions, I
> > have for example 2 tables. TableA and TableB (mind my names), The
> > tables Look like so:
>
> > TableA
> > ----------
> > Id
> > Name
> > RowVersion
>
> > TableB
> > ----------
> > Id
> > TableAId
> > Name
> > RowVersion
>
> > I have a service method which inserts a new TableB, this talks to my
> > repository to do an insert.
>
> > public void Insert(TableB entity) {
> > entity.Validate();
> > repository.Insert(entity);
> > }
>
> > No here is my issue, on my view I am passing in a new TableB like
> > this, the below is a view method which builds up the entity and passes
> > off to the service:
>
> > // Build entity
> > TableB entity = new TableB();
> > entity.Id = view.Id;
> > entity.TableA = new TableA() {
> > Id = view.TableAId;
> > };
> > entity.Name = view.Name;
> > entity.RowVersion = view.RowVersion;
>
> > // Pass to service
> > service.Insert(entity);
>
> > With mapping the TableA relationship I am just setting the Id hoping
> > NH will sort it out, but due to the rowversion is null it thinks it is
> > transient so it is creating a new TableB entity. One solution I came
> > up with was in my presenter use the TableA service to resolve by Id
> > and attach, this works fine, but puts this login in my presenter
> > (yuck).
>
> > So my current solution is to change my service method to check if the
> > TableA's Id is set then use the repository for TableA to resolve by Id
> > and then attach it like this. Seems to work ok for now.
>
> > Has anyone got any suggestions for me on this topic on how I can make
> > this easier?
>
> > Cheers
> > Stefan
>
> --
> Fabio Maulo
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---