views:

8

answers:

1

I am using NHibernate on a project. The database is required to have creation date and creator user fields on relation tables but I do not want to map the relations to domains. My db design is like:

school (id, name, credate, creuser)
student (id, name, credate, creuser)
school_student(id, school_id, student_id, credate, creuser)

For school_student.id, I use autoincrement, pk, not null, so I do not have to map it. NHibernate automatically manages relations so I do not have to map school_id and student_id. For credate, I can use getdate() function, so I do not have to map this field.

But for creuser field, I cannot think of a way that so I do not have to create a domain class for school_student table. How can I escape creating a domain for school_student table? Is there a way of sending creuser information to database each time NHibernate inserts a recort into this table?

A: 

You can use SUSER_SNAME() as the default for the column if it's a direct connection.

Indirectly (eg via a web site) you'll have to send the value of Context.User.Identity because the DB engine does not know who the end user is. You'll have to map it in nHibernate.

gbn
But this is a web app and every user uses the same connection string.
Serhat Özgel