These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: custom inheritance mapping C#->SQL Server
PostPosted: Thu Mar 18, 2010 9:12 am 
Newbie

Joined: Thu Mar 18, 2010 8:54 am
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.