NHibernate version: 1.0.2.0
Hi,
I have the following tables:
Code:
_____________________
|Bank |
|---------------------|
|id : Guid |
|bankname : wchar(200)|
|_____________________|
|
|
/|\
_____________________
|Constraint |
|---------------------|
|id : Guid |
|id_bank : Guid |
|note : wchar(200) |
|_____________________|
Every bank can have 0 ore more constraints.
I mapped that as like this:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="BankManager" assembly="BankManager">
<class name="Bank" table="Bank">
<id name="Id" type="System.Guid" unsaved-value="00000000-0000-0000-0000-000000000000">
<column name="id" sql-type="Guid" not-null="true" />
<generator class="guid" />
</id>
<property name="BankName">
<column name="bankname" length="200" not-null="true"/>
</property>
<list name="Constraints" table="Constraint">
<key column="id_bank" />
<index column="id" type="Guid"/>
<one-to-many class="Constraint" />
</list>
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="BankManager" assembly="BankManager">
<class name="Constraint" table="Constraint">
<id name="Id" column="id" type="System.Guid" unsaved-value="00000000-0000-0000-0000-000000000000">
<generator class="guid" />
</id>
<property name="Name">
<column name="name" length="200" not-null="false"/>
</property>
<property name="Note">
<column name="note" length="200" not-null="false"/>
</property>
</class>
</hibernate-mapping>
When I call
Code:
session.CreateCriteria(typeof(Bank)).List();
the following error occured.
Code:
{"Could not cast the value in field id__ of type Guid to the Type Int32Type. Please check to make sure that the mapping is correct and that your DataProvider supports this Data Type."}
The inner exception say:
Code:
{"Unable to cast object of type 'System.Guid' to type 'System.IConvertible'."}
Why does the engine tries to convert a guid to Int? It couldn't be converted to int and it doesn't implement System.IConvertible.