开发者

Implement nhibernate. Class + abstract base class

I have the following database setup:

Implement nhibernate. Class + abstract base class

I need a nhibernate file that maps it to:

  • PowerPrognosisUsageSubmission class
  • PowerPrognosisWindSubmission class
  • PowerPrognosisSubmissionBase 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜