I have an entity class that I use to represent the results of an sql-query. The mapping for the class shown below. Yet as far as I can tell nhiberate treats the mapping as if there is a real database table - when in fact there is not. In this case there is nothing in the database that represents this entity at all. I am using this to map a query through, but the same would be true of a view. Is there no way to indicate to nhibernate that there isn't a table represented by the mapping?
<class name="Models.UserTransaction"> <!-- Defaults table name same as Entity even though table doesn’t exist -->
<id name="Id">
<column name="Id" not-null="true" unique="true" />
<generator class="native" />
</id>
<property name="TransType" />
<property name="Date" />
<property name="Amount" />
<property name="Balance" />
</class>
This is the query I am mapping, which uses a user defined table. I couldn't get it working without having a mapping even though the example I copied appeared to.
<sql-query name="UserTransactions">
<query-param name="userId" type="string" />
<return class="Models.UserTransaction" alias="userTx">
<return-property name="TransType" column="TransType" />
<return-property name="Id" column="Id" />
<return-property name="Date" column="TransDate" />
<return-property name="Amount" column="Amount" />
<return-property name="Balance" column="Balance" />
</return>
<![CDATA[
SELECT userTx.[Type] as TransType, userTx.[Id] as Id, userTx.[Date] as TransDate, userTx.[Amount] as Amount, userTx.[Balance] as Balance
FROM dbo.User_AccountStatement(:userId) userTx
]]>
</sql-query>