2012-03-15 34 views
1

我正在使用Spring.NET AOP来确定何时C#持久对象具有更改其任何属性(Spring.AopQuickStart.Step6.2010 Spring.NET/examples中),但我得到一个MappingException - 没有留存为:DecoratorAopProxy_8aa4d47e877a48b4828bf7a6a51bbedf配置NHibernate使用Spring.NET AOP代理对象

这里是我的代码:

var person = Repository.GetById(personId); 
var personProxy = GetProxy(person); 
// udpate some properties in personProxy - this is where my advisor determines if/what has changed 
Repository.Save(personProxy); // exception thrown here 

这里是GetProxy样子(每AopQuickStart为例):

private static Person GetProxy(Person target) 
{ 
    var proxyFactory = new Spring.AOP.Framework.ProxyFactory(target); 
    proxyFactory.AddAdvisor(new ModificationAdvisor(target.GetType())); 
    proxyFactory.AddIntroduction(new IsModifiedAdvisor()); 
    proxyFactory.ProxyTargetType = true; 

    return (Person)proxyFactory.GetProxy(); 
} 

我认为问题是传递给NHibernate的会话保存的对象的GetType是“DecoratorAopProxy”,而不是Person抛出NHibernate关闭。

我该如何解决这个问题?

回答

0

看看DataBindingIntercepter.cs的实施和DataBindingFactory.cs

https://github.com/ayende/Effectus/tree/master/Effectus/Infrastructure

+1

完美! (a)通过继承NHibernate.EmptyInterceptor(或实现IInterceptor)创建一个自定义拦截器,(b)重写它的GetEntityName()以返回适当的类型而不是代理,并且(c)设置你的自定义创建NHibernate.Cfg.Configuration时的拦截器。 – rtorres 2012-03-18 19:18:42

相关问题