为内嵌类(Nested Class)配置NHibernate的O/R Mapping文件
对于内嵌类的hibernate-mapping,如果用MyParentClass.MyNestedClass指定类名将会引发如下的异常:
NHibernate.MappingException : associated class not found
----> System.TypeLoadException : 未能从程序集 MyAssembly 中加载类型 MyParentClass.MyNestedClass。
从源代码可看到,NHibernate的Binder类最终调用的是System.Type.GetType这个方法,参考微软MSDN的文档,这个方法的typeName参数,关于内嵌类的语法是MyParentClass+MyNestedClass,因此指定类名用“.”语法就引发了异常。
同时要注意文件名也应该采用这种语法,即MyParentClass+MyNestedClass.hbm.xml。
参考文档:
http://msdn2.microsoft.com/library/w3f99sx1(en-us,vs.80).aspx
NHibernate.MappingException : associated class not found
----> System.TypeLoadException : 未能从程序集 MyAssembly 中加载类型 MyParentClass.MyNestedClass。从源代码可看到,NHibernate的Binder类最终调用的是System.Type.GetType这个方法,参考微软MSDN的文档,这个方法的typeName参数,关于内嵌类的语法是MyParentClass+MyNestedClass,因此指定类名用“.”语法就引发了异常。
同时要注意文件名也应该采用这种语法,即MyParentClass+MyNestedClass.hbm.xml。
参考文档:
http://msdn2.microsoft.com/library/w3f99sx1(en-us,vs.80).aspx
浙公网安备 33010602011771号