Given a parent child relationship between User
and FailedLogin
where a user has many failed logins. I'd like to map this into
class User
{
public virtual FailedLogin LastFailedLogin { get; set; }
}
class FailedLogin
{
public virtual User User { get; set; }
public virtual DateTime AttemptOn { get; set; }
}
So that the LastFailedLogin
property contains the FailedLogin
with the most recent AttemptOn
date and time. If LastFailedLogin
is set it should save that FailedLogin
to the database (i.e. .Cascade.SaveUpdate()
) Note, I do not want to map a collection of all FailedLogins for this user for performance reasons.
I have been totally unable to write a fluent mapping for this. How do I map this using Fluent NHibernate?
public class UserMap : ClassMap<User>
{
public UserMap()
{
// What goes here for LastFailedLogin?
}
}
public class FailedLoginMap: ClassMap<FailedLogin>
{
public FailedLoginMap()
{
References(x => x.User).Not.Update();
Map(x => x.AttemptOn).Not.Update();
}
}