Re: [nhusers] Archive data Joe Brockhaus Mon Feb 06 12:00:23 2012
I'm not sure how you are expecting this to work in only a single table. In your example, you left out the crucial PK (Emp_id) from the data. >> .. then the table will look like ... It looks like you are suggesting the table will have a duplicated row for each modification? This itself seems flawed. How do you distinguish the rows from versioning rows or actual other data? For this archive data, I would recommend a separate table, Employee_Archive. (This would be independent of NHibernate) -- Employee_Archive should have every field from the Employee table, and one additional: ArchiveID (the PK of the _Archive table) -- create a trigger on the Employee table. ---- 'before update' --> insert the existing row from Employee into the Employee_Archive table, generating a new ArchiveID each time. -- then allow the update to occur as normal. By doing this: -- your Employee table will have 1 row per employee, as expected. -- your archive table will have 1 row for every change to that employee. You don't need to do anything funky in NHibernate to have it do this. Then, you should create another entity to query this archive table that is mapped explicitly to it. ------ Joe Brockhaus [EMAIL PROTECTED] ------------ On Mon, Feb 6, 2012 at 2:00 PM, Ankita Kumar <[EMAIL PROTECTED]> wrote: > Hi, > > I want to know can i customize the insert operation? I have a table > say Employee with columns Emp_id,Emp_Name,Dept, StartDate, EndDate and > UpdatedBy. We have the last three column to keep track of all the > chnages made on a record, since it insert in the table. > Like on 3rdJan2011, I inserted a record ABC, IT Dept, 03-01-2011, > null ,UpdatedByUser > > If on 5th Jan, I updated the record , then the table will look like > ABC, IT Dept, 03-01-2011, 05-01-2011,UpdatedByUser > ABC, IT Dept, 05-01-2011, null ,UpdatedByUser > > Note: That the latest record will always have null in the end date. > > Well this is the logic that I need to implement while inserting the > record in the database. Can someone help me on how I can acheive it in > NHibernate? > > -- > 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. > > -- 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.