Hello NHibernate-users
I would like to map to a SortedList in the .NET Framework Class Library, but I can’t find useful information concerning this matter.
A Group has multiple Categories. But the ordering of the Category-items within a Group is not based on a property of the Category business entity. No, a column in the Categories-table (Cat_PositionInGrp) maintains the key for ordering the Categories-items within a Group. As a result, I decided to use a SortedList(Of Integer, bsCategory). The user should be allowed to change this ordering at all time.
Herewith the code of both the Group- and Category business entity classes:
Code:
Public Class bsGroup
Private mId As Integer
Private mName As String
Private mCategories As SortedList(Of Integer, bsCategory)
Public Overridable Property Id() As Integer
Get
Return mId
End Get
Set(ByVal value As Integer)
mId = value
End Set
End Property
Public Overridable Property Name() As String
Get
Return mName
End Get
Set(ByVal value As String)
mName = value
End Set
End Property
Public Overridable Property Categories() As SortedList(Of Integer, bsCategory)
Get
Return mCategories
End Get
Set(ByVal value As SortedList(Of Integer, bsCategory))
mCategories = value
End Set
End Property
#End Region
End Class
Code:
Public Class bsCategory
Private mId As Integer
Private mName As String
Public Overridable Property Id() As Integer
Get
Return mId
End Get
Set(ByVal value As Integer)
mId = value
End Set
End Property
Public Overridable Property Name() As String
Get
Return mName
End Get
Set(ByVal value As String)
mName = value
End Set
End Property
End Class
A brief overview of the necessary tables and its columns in SQL Server 2005:
Code:
CREATE TABLE [dbo].[TBL_GROUPS](
[Grp_Id] [int] IDENTITY(1,1) NOT NULL,
[Grp_Name] [nvarchar](50) NOT NULL,
CREATE TABLE [dbo].[TBL_CATEGORIES](
[Cat_Id] [int] IDENTITY(1,1) NOT NULL,
[Cat_Grp_Id] [int] NOT NULL,
[Cat_PositionInGrp] [int] NOT NULL,
[Cat_Name] [nvarchar](50) NOT NULL,
I can not imagine that a .Net SortedList cannot be mapped through NHibernate. Or am I wrong?