Hi,
I try to create a mapping and the associated code for an ordered list
but … without success.
Here is my situation. I have 2 tables:
BalanceSheet
- BalanceSheetID INT PRIMARY KEY IDENTITY(1,1)
- BalanceSheetName VARCHAR(25) NOT NULL
BalanceSheetCategories
- BalanceSheetID INT NOT NULL
- CategoryIndex INT NOT NULL
- CategoryName VARCHAR(25) NOT NULL
CONSTRAINT PK_BalanceSheetCategory PRIMARY KEY (BalanceSheetID ASC,
CategoryIndex ASC)
What I want to do:
I want to manipulate a BalanceSheet object that contains an ordered
list of categories:
- read a BalanceSheet object
- read its ordered categories list with lazy loading
- add or remove some categories and save the new list
- …
Here the cartography that I created (I suppose that it is correct):
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="BankAccountForWindows.Domain.BalanceSheet,
BankAccountForWindows.Domain" table="BalanceSheet">
<id name="Id" column="BalanceSheetID" access="field.lowercase-
underscore" type="int">
<generator class="identity" />
</id>
<property name="BalanceSheetName" type="string" />
<list name="OrderedCategories" table="BalanceSheetCategory"
lazy="true" access="field.camelcase-underscore">
<key column="BalanceSheetID"/>
<index column="CategoryIDIndex" />
<element type="string" column="CategoryName"
not-null="true" />
</list>
</class>
</hibernate-mapping>
And now, the code (I have removed some stuff that was not necessary):
<Serializable()> _
Public Class BalanceSheet
Implements IBalanceSheet
Private _balanceSheetID As Integer = 0
Private _balanceSheetName As String = String.Empty
Private _orderedCategories As IList(Of IOrderedCategory) = New
List(Of IOrderedCategory)
Public Sub New()
…..
End Sub
Public ReadOnly Property BalanceSheetID() As Integer
Implements IBalanceSheet.BalanceSheetID
Get
Return _balanceSheetID
End Get
End Property
Public Property BalanceSheetName() As String Implements
IBalanceSheet.BalanceSheetName
Get
Return _balanceSheetName
End Get
Set(ByVal value As String)
_balanceSheetName = value
End Set
End Property
Public Property OrderedCategories() As IList(Of
DomainInterfaces.IOrderedCategory) Implements
IBalanceSheet.OrderedCategories
Get
Return _orderedCategories
End Get
Set(ByVal value As IList(Of
DomainInterfaces.IOrderedCategory))
_orderedCategories = value
End Set
End Property
End Class
<Serializable()> _
Public Class OrderedCategory
Implements IOrderedCategory
Private _balanceSheet As IBalanceSheet = Nothing
Private _categoryIDIndex As Integer = 0
Private _category As String = String.Empty
Public Sub New()
…..
End Sub
Public Property BalanceSheet() As IBalanceSheet Implements
IOrderedCategory.BalanceSheet
Get
Return _balanceSheet
End Get
Set(ByVal value As IBalanceSheet)
_balanceSheet = value
End Set
End Property
Public Property CategoryIDIndex() As Integer Implements
IOrderedCategory.CategoryIDIndex
Get
Return _categoryIDIndex
End Get
Set(ByVal value As Integer)
_categoryIDIndex = value
End Set
End Property
Public Property CategoryName() As String Implements
IOrderedCategory.CategoryName
Get
Return _category
End Get
Set(ByVal value As String)
_category = value
End Set
End Property
End Class
When I run the following unit test, I have an error:
<Test()> _
Public Sub BasicSave ()
'Setup
Dim balanceSheet As New BalanceSheet("BalanceSheet")
'Adding some categories
balanceSheet.OrderedCategories.Add(New OrderedCategory
(balanceSheet, 2, "Catégorie 2"))
balanceSheet.OrderedCategories.Add(New OrderedCategory
(balanceSheet, 1, "Catégorie 1"))
balanceSheet.OrderedCategories.Add(New OrderedCategory
(balanceSheet, 0, "Catégorie 0"))
'Action
balanceSheet.Save()
'Verification
...
End Sub
The error (I have translated from French):
NHibernate.ADOException: could not insert collection:
[BalanceSheet.OrderedCategories#2] ---> System.InvalidCastException:
Conversion failure of the value of parameter OrderedCategory in
String. ---> System.InvalidCastException: The object must implement
IConvertible.
I really don’t understand what is wrong!
Is anybody has an idea?
Thanks.
Gérard
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---