Similar to AdventureWorks' EmployeePayHistory. Just use protected internal to hide that ORM low-level plumbing concern
public class PersonPayHistory
{
PersonPayHistoryCompositePK _pk = new PersonPayHistoryCompositePK();
protected internal PersonPayHistoryCompositePK PersonPayHistoryCompositePK
{
get { return _pk; }
set { _pk = value; }
}
Person _person;
public virtual Person Person
{
get { return _person; }
set
{
_person = value;
_pk.PersonId = _person.PersonId;
}
}
public virtual DateTime RateDate
{
get { return _pk.RateDate; }
set { _pk.RateDate = value; }
}
public virtual decimal Rate { get; set; }
}
So we will not make the mistake of saving our entity through those composite primary key:
var ph = new PersonPayHistory
{
Person = session.Load<Person>(1),
RateDate = DateTime.Today,
Rate = 1337M
};
session.Save (ph);
session.Flush ();
No comments:
Post a Comment