1. 持久对象映射文件关于持久对象映射文件,这里就不多说了,可参考nhibernate的例子与文档.在nhibernate源代码的根目录里有一个nhibernate-mapping-2.0.xsd文档,这个文档是nhibernate用来对映射文件进行验证的,我们也可以借助相关软件用这个文档来验证映射文件的有效性.2. 映射信息的读取通过configuration类,可以用多种方式读取映射信息,一些以add开头的方法就是用来加入映射信息的,这些方法最终将调用add(xmldocument doc).//** configuration.cs **private hashtable classes = new hashtable();classes集合用于存放所有的持久对象映射信息,它的key为持久类的类型;value为permissionclass类的子类.private void add(xmldocument doc) { try { binder.dialect = dialect.dialect.getdialect(properties); binder.bindroot( doc, createmappings()); } catch (mappingexception me) { log.error("could not compile the mapping document", me); throw me; } // end try/catch}adddocument方法调用binder的静态方法bindroot来绑定持久类映射信息.createmappings返回一个mappings对象,此对象是一个简单封装了所有映射信息集合的类.3. 建立对象映射信息binder类的bindroot用于绑定映射信息中的所有映射内容.//** binder.cs **public static void bindroot(xmldocument doc, mappings model) { // ... foreach(xmlnode n in hmnode.selectnodes(nsprefix + ":class", nsmgr) ) { rootclass rootclass = new rootclass(); binder.bindrootclass(n, rootclass, model); model.addclass(rootclass); } // ...}遍历所有的类映射节点,然后调用bindrootclass来绑定类映射信息,最后将类映射信息加到集合中.其中rootclass为permissionclass的子类.... 下一页