निम्नलिखित कोड डालने पर काम करता है लेकिन अद्यतन पर modifier
कभी भी सेट नहीं है, कोई विचार क्यों?अद्यतन पर घटनाओं के साथ nhibernate लेखा परीक्षा
प्री-अपडेट के लिए कोड चलाया जा रहा है और वांछित मूल्य पर राज्य और इकाई मानों को सही ढंग से सेट करता है। हालांकि जेनरेट किए गए एसक्यूएल निबर्ननेट को देखते समय अद्यतन क्वेरी में फ़ील्ड शामिल नहीं होता है।
/// <summary> Updates auditable objects </summary>
public class AuditEventListener : IPreInsertEventListener, IPreUpdateEventListener
{
private ISecurityManager securityManager;
public bool OnPreInsert(PreInsertEvent args)
{
var auditable = args.Entity as IAuditable;
if (auditable != null) {
Set(x => auditable.Creator, args.Persister, auditable, args.State, SecurityManager.Identity);
Set(x => auditable.DateAdded, args.Persister, auditable, args.State, Clock.Now);
}
return false;
}
public bool OnPreUpdate(PreUpdateEvent args)
{
var auditable = args.Entity as IAuditable;
if (auditable != null) {
Set(x => auditable.Modifier, args.Persister, auditable, args.State, SecurityManager.Identity);
//Set(x => auditable.DateModified, args.Persister, auditable, args.State, Clock.Now);
}
return false;
}
/// <summary> Type safe method to update sate and entity </summary>
private void Set<T, U>(Expression<Func<U, T>> expression, IEntityPersister persister, U instance, object[] state, T value)
{
var member = expression.Body as MemberExpression;
if (member != null) {
var index = Array.IndexOf(persister.PropertyNames, member.Member.Name);
if (index == -1) {
return;
}
state[index] = value;
var property = (member.Member as PropertyInfo);
if (property != null) {
property.SetValue(instance, value, null);
}
}
}
ISecurityManager SecurityManager
{
get { /* From IoC */ }
}
}
यह कोड मुझे ठीक लग रहा है, हालांकि सेट विधि असामान्य है। यदि आप OnPreUpdate पर ब्रेकपॉइंट डालते हैं तो क्या आप एक अद्यतन ऑब्जेक्ट जारी रखते समय इसे कॉल कर रहे हैं? –
हां, मुझे लगता है कि समस्या के साथ उस संपत्ति के साथ कुछ करने के लिए कुछ नहीं है जिसे नफरत से गंदे माना जाता है। –