How to map this type of subclass container situation in Nhibernate. Help me providing the mapping xml structure
My Class Strucutre
public class Employee
{
public virtual int EmpID;
public virtual string EmpName;
public virtual Audit AuditDetails;
}
public class Audit
{
public virtual User CreatedBy;
public virtual DateTime CreatedOn;
public virtual User ModifiedBy;
public virtual DateTime ModifiedOn;
}
public class User
{
public virtual int UserID;
public virtual string FullName;
public virtual Audit AuditDetails;
}
My database table structure
Employee
EmpID(int pk) | EmpName(varchar) | CreatedBy(int) | ModifiedBy(int) | CreatedOn(date) | ModifiedOn(date)
User
UserID (int pk) | FullName(varchar) | CreatedBy(int) | ModifiedBy(int) | CreatedOn(date) | ModifiedOn(date)
Using NHibernate and C# I wish to solve this situation.
Most of my tables contain the Audit detials (creator, Modifier and datetimes of them)
I wish to map in such a way that the Userid should be saved as the CreatedBy and ModifiedBy fields and for Dates is a direct mapping.
But those all details is a seperate entity called Audit in my class structure.
Please help me by providing a mapping sheet for this type of situation.
Any help is appreciated.
If you want to put your Audit entity in the same tables, you will need to use
<component>. Here’s a tutorial:http://ayende.com/blog/3937/nhibernate-mapping-component