I have two entities, Test1, and Test2; Please refer
Code:
public class Test1
{
public virtual string Id { get; set; }
public virtual string Name { get; set; }
public virtual ISet<Test2> Test2s { get; set; }
}
public class Test2
{
public virtual string Id { get; set; }
public virtual string Description { get; set; }
public virtual Test1 Test1 { get; set; }
}
and the Nhibernate configuration for them as following:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Usky.ECommerce.Model.Test.Test1,Usky.ECommerce.Model" table="YJLUO_TEST1">
<id name="Id" column="Id">
<generator class="uuid.hex" />
</id>
<property name="Name" length="20" type="String" not-null="true"/>
<set name="Test2s" inverse="true" cascade="all" generic="true" lazy="true">
<key column="Test1ID" not-null="true"/>
<one-to-many class="Usky.ECommerce.Model.Test.Test2,Usky.ECommerce.Model"/>
</set>
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Usky.ECommerce.Model.Test.Test2,Usky.ECommerce.Model" table="YJLUO_TEST2">
<id name="Id" column="Id">
<generator class="uuid.hex" />
</id>
<property name="Description" length="200" type="String"/>
<many-to-one name="Test1" column="TEST1ID" class="Usky.ECommerce.Model.Test.Test1,Usky.ECommerce.Model" not-null="false"></many-to-one>
</class>
</hibernate-mapping>
I want to get Test2 by its Description, via
Code:
Test2 t2 = Find(" from Test2 t2 where t2.Description = ?", "AddTest1WithTest2", NHibernate.NHibernateUtil.String)[0];
Then I the Exception is raised as the title, more detais is "Invalid Cast (check your mapping for property type mismatches); setter of Usky.ECommerce.Model.Test.Test2".