Hi I am trying to keep common properties of base class in one location and use XML ENTITY to refer in Nhibernate mapping file.
Mapping file
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE hibernate-mapping [
<!ENTITY BasePropertyList SYSTEM "BasePropertyList.xml">
]>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="Model" namespace= "Model" default-lazy="false">
<class name="DerivedClass">
&BasePropertyList;
</class>
</hibernate-mapping>
BasePropertyList.xml
<id name="ID" column="ID" type="Int32" unsaved-value="0">
<generator class="native"></generator>
</id>
<property name="CreatedDate" update="false" />
<property name="CreatedBy" update="false" />
<property name="LastModifiedDate" />
<property name="LastModifiedBy" />
I am getting following exception
System.Xml.XmlException : DTD is prohibited in this XML document. at NHibernate.Cfg.Configuration.Log开发者_开发问答AndThrow(Exception exception)
Am I missing anything here? How DOCTYPE works in Nhibernate mapping file??
I don't know how to solve the doctype issue, but I have never that it was a feature.
If you want to map inheritance, you can use one of the three strategies described in The documentation
In your case, table per class is probably the best way of mapping. That means duplicated xml in each mapping file. I don't think there is a way to avoid that, except recreating the xml with some macro or build script when the base class changes (which isn't a real way to avoid the problem). You can also avoid the problem by using FluentNhibernate instead of xml and inherit the ClassMap<> class for the base type (that's what I personally do when I have a common base class in a project).
If you want to be able to query the properties of all objects in the database in one query, you might like the table per subclass mapping strategy. Table per subclass doesn't require the duplicated xml, but adds a sql join to the query.
It is broken in the current release. I had the same problem and i have tested versions 2.0.1, 2.1.0, 2.1.1, 2.1.2 and it was broken
If i read this correctly, its not going to be fixed and it seems that it is a left over in the reference documentation
精彩评论