All my NH objects are obtained from the BusinessEntity type, this has the most basic values โโof ID, Created, CreatedBy, Updated, Updated .By.
CreatedBy / updatedBy accepts user
I have an IPreUpdateEventListener and IPreInsertEventListener that fire to get the current DateTime for audit values. Also here I have my logic to launch the current user that I grabbed by running the query criteria for the Windows user principle. From what I understand from all the messages in the NH user group on this subject, I need a custom class to be impatiently loaded so that it works correctly in my EventListeners, this is how I load the user
public User GetByDomainPrinciple(string domainPrinciple) { var domainPrincipleCriteria = DetachedCriteria.For<User>() .Add(Restrictions.Eq("DomainPrinciple", domainPrinciple)) .SetFetchMode("Roles", FetchMode.Eager) .SetFetchMode("Groups", FetchMode.Eager) .SetFetchMode("Groups.Roles", FetchMode.Eager) .SetCacheable(true); return Repository.QuerySingle(domainPrincipleCriteria); }
Repository.QuerySingle(domainPrincipleCriteria); just
return detachedCriteria .GetExecutableCriteria(_conversation.Session).UniqueResult<T>();
Am I missing something or incorrectly responding to my criteria? I think absolute. In the worst case scenario, I could change CreatedBy as a Guid and not a User and just assign an FK that way, but it seems very dirty.
c # exception nhibernate
Chris marisic
source share