I have the following database setup:
I need a nhibernate file that maps it to:
PowerPrognosisUsageSubmission
classPowerPrognosisWindSubmission
classPowerPrognosisSubmissionBase
abstract base class
Although, I am getting nowhere. Here is my attempt:
I tried implementing PowerPrognosisUsageSubmission
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping namespace="DC.Client.Models.Model" assembly="DC.Client.Models" xmlns="urn:nhibernate-mapping-2.2">
<class name="PowerPrognosisUsageSubmission" table="PowerPrognosisSubmissionBase" schema="`dbo`" mutable="true" lazy="false">
<id name="PowerPrognosisSubmissionId" access="property" column="`PowerPrognosisSubmissionBaseID`">
<generator class="native" />
</id>
<property name="Date" column="`Date`" />
<property name="Hour" column="`Hour`" />
<property name="Direction" column="`Direction`" />
<property name="Submission" column="`Submission`" />
<property name="Basis" column="`Basis`" />
<many-to-one name="PowerPrognosisUsageArea" class="PowerPrognosisUsageArea" column="`PowerPrognosisAreaBaseID`" not-null="false" lazy="false" />
<joined-subclass name="PowerPrognosisUsageSubmission" table="PowerPrognosisUsageSubmission">
<key column="`Usage`" />
</joined-subclass>
</clas开发者_C百科s>
</hibernate-mapping>
Any help?
I solved it on my own
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping namespace="DC.Client.Models.Model" assembly="DC.Client.Models" xmlns="urn:nhibernate-mapping-2.2">
<class name="PowerPrognosisSubmissionBase" table="PowerPrognosisSubmissionBase" schema="`dbo`" mutable="true" lazy="false">
<id name="PowerPrognosisSubmissionId" access="property" column="`PowerPrognosisSubmissionBaseID`">
<generator class="native" />
</id>
<property name="Date" column="`Date`" />
<property name="Hour" column="`Hour`" />
<property name="Direction" column="`Direction`" />
<property name="Submission" column="`Submission`" />
<property name="Basis" column="`Basis`" />
<many-to-one name="PowerPrognosisAreaUsage" class="PowerPrognosisAreaUsage" column="`PowerPrognosisAreaBaseID`" not-null="false" lazy="false" />
<joined-subclass name="PowerPrognosisSubmissionUsage" table="PowerPrognosisSubmissionUsage">
<key column="`PowerPrognosisSubmissionBaseID`" />
<property name="Usage" column="`Usage`" />
</joined-subclass>
<joined-subclass name="PowerPrognosisSubmissionWind" table="PowerPrognosisSubmissionWind">
<key column="`PowerPrognosisSubmissionBaseID`" />
<property name="PriceAreaEffect" column="`PriceAreaEffect`" />
<property name="ResponsibleEffect" column="`ResponsibleEffect`" />
<property name="W2UShare" column="`W2UShare`" />
<property name="PointCarbonShare" column="`PointCarbonShare`" />
</joined-subclass>
</class>
</hibernate-mapping>
I would suggest you take a look at FluentNhibernate, in my opinion, it gives a much better way to mapping tables to your entity classes.
Also, you might wanna give this tool a go, it's capable of generating hbm.xml or fluentnhibernate mapping files for you.
http://nmg.codeplex.com/
Maybe you should read the NHibernate manual. Chapter 8 has all the details on inheritance.
精彩评论