In our project we use custom Inheritance mapping
For example:
Code:
public class Channel
{
public int ID
{
get;
set;
}
public String Name
{
get;
set;
}
public int Timeout
{
get;
set;
}
}
public class HttpChannel : Channel
{
public string AuthMode
{
get;
set;
}
public int AuthParams
{
get;
set;
}
public int Uri
{
get;
set;
}
}
In Sql Server we have following tables:
Code:
CREATE TABLE [dbo].[Channel](
[id] [int] IDENTITY(1,1) NOT NULL,
[Name] [varchar](200) NULL,
[Timeout] [int] NULL,
[type] [varchar](20) NULL,
CONSTRAINT [PK_Channel] PRIMARY KEY CLUSTERED ([id] ASC)
)
CREATE TABLE [dbo].[object_params](
[id] [int] IDENTITY(1,1) NOT NULL,
[table] [varchar](50) NOT NULL,
[object_id] [int] NOT NULL,
[name] [varchar](50) NOT NULL,
[value] [varchar](500) NULL,
CONSTRAINT [PK_object_params] PRIMARY KEY CLUSTERED ([id] ASC)
)
Properties of descendant types stored in object_params table
Sql query that inserts new HttpChannel:
Code:
declare @id int
insert into channel ([name], [timeout], [type]) values ('channel', 60, 'HttpChannel')
set @id = scope_identity()
insert into object_params ([table], [object_id], [name], [value]) values ('channel', @id, 'AuthMode', 'basic')
insert into object_params ([table], [object_id], [name], [value]) values ('channel', @id, 'AuthParams', 'user:user')
insert into object_params ([table], [object_id], [name], [value]) values ('channel', @id, 'uri', 'http://')
Sql query to load all HttpChannels from DB:
Code:
select
*,
dbo.GetField('channel', channel.id, 'AuthMode') as AuthMode,
dbo.GetField('channel', channel.id, 'AuthParams') as AuthParams,
dbo.GetField('channel', channel.id, 'Uri') as Uri
from channel where [type] = 'HttpChannel'
UDF GetField() returns property value from object_params table.
Can I realize such model in NHibernate? i know that is bad performance solution, but satisfies our needs.
P.S.: Sorry for my English