Hello,

 

I have used nhibernate before and I love it, however the time has arrived
where I am trying to use nhibernate with a complex legacy db K there is a
recurring theme in the db which I can't figure out how to map/change db in a
way that doesn't break existing apps using the db.

 

We have 2 tables in the db, Account and AccountSetting

 

Account table columns:

AccountId int, PK

AccountSettingIndex int, not null  (this is like a version column on the
AccountSetting table, except instead of updating this value in the
AccountSetting table, a new row is created for each update that has a change
in the account setting to store historical data)

Some other columns

 

AccountSetting table:

AccountId int, PK

AccountSettingIndex int PK

AccountType int (maps to accountTypes table, discriminator column)

Type1and2UsedColumn string (used in 2 account types)

Type1AccountColumn string  (column only used if AccountType is 1)

Type2AccountColumn string  (column only used if AccountType is 2)

 

The way it is used in the current system, is a stored procedure that
retrieves the account and account setting data by doing a join on the
AccountId and AccountSettingIndex. When an update occurs, a new row is
created in the AccountSetting table (AccountSettingIndex is manually
incremented) and the value of the AccountSettingIndex on the accounts table
is updated to the value of AccountSettingIndex in the new AccountSetting
row.

 

What I am trying to achieve is to have Classes that map to the join of the
Account and AccountSetting table:

 

Class Type1Account{

string Type1and2UsedColumn;

string Type1AccountColumn;

}

 

Class Type2Account{

string Type1and2UsedColumn;

string Type2AccountColumn;

}

 

I guess there would be an abstract BaseAccount class with the Ids. There are
other tables in the database that reference the AccountTable by AccountId

 

Not sure how to go about this,  main problem I see is that the primary key
of the 2 tables is different and the fact that we want the update to perform
an insert on the AccountSetting table.

 

I thought about having a pre-update listener that would add the new to the
accountsetting table instead of updating (never done this before, not sure
it would work), but how would I add an AccountSetting row, is there is no
class mapped for that specific table.

 

Any feedback would be appreciated, hints, links, anything as this method was
used for many tables in the db (User, UserSetting which has
UserSettingIndex....)! 

 

 

 

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