I have this native sql statement that I need mapped to a property.
I want a property that I need to contain a List<Device> populated by a native sql statement. I noticed that the property attribute allows custom sql formulas. Unfortunately, nHibernate is wrapping my stored procedure in a select GROUP query, not even a select device query. Take a look at my code below:
Below is my mapping file for
Group.hbm.xml:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="DataServices.BusinessEntities"
namespace="DataServices.BusinessEntities">
<class name="Group" table="Groups">
<id name="Id" type="Int32" column="Id" access="property">
<generator class="identity">
<param name="table">Extensions</param>
<param name="column">Id</param>
</generator>
</id>
<property name="Name" column="Name"/>
<property name="Description" column="Description"/>
<property name="AllDevices" type="DataServices.BusinessEntities.Device, DataServices.BusinessEntities" formula="(dbo.GetAllDevicesInGroup(id))">
</property>
</class>
</hibernate-mapping>
Device.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="DataServices.BusinessEntities"
namespace="DataServices.BusinessEntities">
<class name="Device" table="Devices">
<id name="Id" type="Int32" column="Id" access="property">
<generator class="identity">
<param name="table">Devices</param>
<param name="column">Id</param>
</generator>
</id>
<property name ="Name" column="Name"/>
<property name ="Description" column="Description"/>
</class>
</hibernate-mapping>
When I try to get a group from the database, I get this:
could not execute query
Code:
[ SELECT this_.Id as Id7_0_, this_.Name as Name7_0_, this_.Description as Descript3_7_0_, (dbo.GetAllDevicesInGroup(this_.id)) as formula0_0_ FROM Groups this_ WHERE this_.Id = ? ]
Positional parameters: #0>2614
[SQL: SELECT this_.Id as Id7_0_, this_.Name as Name7_0_, this_.Description as Descript3_7_0_, (dbo.GetAllDevicesInGroup(this_.id)) as formula0_0_ FROM Groups this_ WHERE this_.Id = ?]
Its wrapping my stored procedure as a GROUP, when I need a DEVICE