Hi,
I am new to NHibernate so pls bear with me......
I'm trying to resolve a problem whereby the SQL query generated by NHibernate has a duplicate column alias which SQL CE clearly doesn't like.
This problem does not occur when querying an SQL 2005 database.
Having compared my mapping files and classes to other examples I can't see why this is happening and would appreciate it if someone could help me out.
Classes are:
ClientReport which inherits from Report
ClientPublication which inherits from Publication
A ClientReport may have one or more ClientPublications
A ClientPublication must belong to a ClientReport
ClientReport mapping:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true">
<class name="ReportDistribution.Client.ReportMgr.Model.ClientReport, ReportDistribution.Client.ReportMgr.Model" table="ClientReport" lazy="false">
<id name="Id" access="property" column="ReportID">
<generator class="native"></generator>
</id>
<property name="MaxAge" access="property" />
<property name="DeleteUnread" access="property" />
<property name="Description" access="property" />
<property name="Name" access="property" />
<bag name="ClientPublications" cascade="all" lazy="false">
<key column="ReportID"></key>
<one-to-many
class="ReportDistribution.Client.ReportMgr.Model.ClientPublication, ReportDistribution.Client.ReportMgr.Model" />
</bag>
</class>
</hibernate-mapping>
ClientPublication mapping:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true">
<class name="ReportDistribution.Client.ReportMgr.Model.ClientPublication, ReportDistribution.Client.ReportMgr.Model" table="ClientPublication" lazy="false" >
<id name="Id" access="property" column="PublicationID">
<generator class="native"></generator>
</id>
<property name="ReportId" access="property"></property>
<property name="CreatedOn" access="property"></property>
<property name="IsMarkedForDeletion" access="property"></property>
<property name="IsDeleted" access="property"></property>
<property name="HasBeenRead" access="property"></property>
<property name="ReceivedOn" access="property"></property>
<property name="FileExtension" access="property"></property>
<property name="IsConverted" access="property"></property>
<property name="IsDownloaded" access="property"></property>
<many-to-one
name="ClientReport"
class="ReportDistribution.Client.ReportMgr.Model.ClientReport, ReportDistribution.Client.ReportMgr.Model"
column="ReportID" lazy="false"
not-null="true">
</many-to-one>
</class>
</hibernate-mapping>
The SQL generate by NHibernate is:
Code:
[SQL: SELECT clientpubl0_.ReportID as ReportID__1_, clientpubl0_.PublicationID as Publicat1_1_, clientpubl0_.PublicationID as Publicat1_0_0_, clientpubl0_.ReportId as ReportId0_0_, clientpubl0_.CreatedOn as CreatedOn0_0_, clientpubl0_.IsMarkedForDeletion as IsMarked4_0_0_, clientpubl0_.IsDeleted as IsDeleted0_0_, clientpubl0_.HasBeenRead as HasBeenR6_0_0_, clientpubl0_.ReceivedOn as ReceivedOn0_0_, clientpubl0_.FileExtension as FileExte8_0_0_, clientpubl0_.IsConverted as IsConver9_0_0_, clientpubl0_.IsDownloaded as IsDownl10_0_0_, clientpubl0_.ReportID as ReportID0_0_ FROM ClientPublication clientpubl0_ WHERE clientpubl0_.ReportID=?]
The duplicated column alias is "ReportId0_0_"
Thanks.