Hey all,

I am trying to map a composite-id to a legacy database of which I have
no access to modify the structure, and I need to perform basic CRUD on
it.

The basic design is that I have 2 columns in the pk:
a tablename_id which is an identity field
and a tablename_db_id which is an id of the instance of the db i am
using.

The decision for this was that there are many instances of the
database in different locations that need to replicate back to the
main office.

i.e. the database id that is assigned to my instance of the db is 16.

My main problem is when I try to create a new item in the table.

I have tried mapping the tablename_id as the id and having the
tablename_id_db as a not null, but this throws an
NHibernate.FKUnmatchingColumnsException 'must have same number of
columns as the referenced primary key'.

I have tried mapping it as a composite-id and setting the value of the
2 fields, but this causes me an System.Data.SqlClient.SqlException:
Cannot insert explicit value for identity column in table 'tablename'
when IDENTITY_INSERT is set to OFF.

So I was thinking of developing a composite-id generator of some sort
with the mapping something like this:

<composite-id>
    <key-property name="Id">
        <column name="tablename_id" sql-type="int" not-null="true" />
    </key-property>
    <key-generated-property name="DatabaseId">
        <column name="tablename_db_id" sql-type="int" not-null="true" /
>
        <generator class="identity" />
    </key-generated-property>
</composite-id>

Any thoughts or some direction in this?

Cheers.

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