My error occurrs when I try to execute the query created based on my mappings. Here is the code.
Code:
return AllGenericLookupValues = session.CreateCriteria(typeof(GenericLookup)).List<GenericLookup>();
However, when I copy and paste the query into sql it works. The reason for this is I am getting an "Unable to cast object of type" error. Is there something I should do differently in my xml files or in my DE files?
I have a parent table "GenericLookup" and a child table "GenericLookupValue". I want the results to be nested.
My GenericLookupBL class calls the GenericLookupRepository in my DAL
When the joined is performed I am referencing properties at the DE level in both the GenericLookup.cs and GenericLookupalue.cs (you should be able to see this in the xml below). If I have not provided enough information please let me know and I will provide more.
**** Here is the contents of my GenericLookup.hbm.xml ****
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping
schema="dbSchema"
xmlns="urn:nhibernate-mapping-2.2"
assembly="assembly"
namespace="namespace.DE">
<class name="GenericLookup" table="GenericLookUp">
<id column="LookupID" name="LookupID">
<generator class="identity" />
</id>
<property column="Name" name="Name" />
<bag name="GenericVal" fetch="join" cascade="all">
<key column="LookupID" />
<one-to-many class="GenericLookupValue" />
</bag>
</class>
</hibernate-mapping>
**** Here is the contents of my GenericLookupValue.hbm.xml ****
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping
schema="dbSchema"
xmlns="urn:nhibernate-mapping-2.2"
assembly="assembly"
namespace="namespace.DE">
<class table="GenericLookupValue" name="GenericLookupValue">
<id name="LookupValueID" type="Int32" column="LookupValueID" unsaved-value="0">
<generator class="identity" />
</id>
<property name="LookupID" />
<property name="Value" />
</class>
</hibernate-mapping>