Hi Walaa,
Sorry for the delay, but that day was just the first day of my vacation. Now I'am back.
Answers:
- I try to create a target per hierarchy inheritance.
- The DDL you've requested is appended to the end of this message.
More info:
I tried it keep as simple as possible. Three entities:
Entity 'Parameter': it is the base class. It has three attributes:
- [ParameterId] [int] NOT NULL,
- [ParameterType] [int] NOT NULL,
- [ParameterValue] varchar NOT NULL,
The discriminator column will be the "ParameterType"
The first descendant entity 'AParameter' should have one more attribute:
which is unfortunetelly a foreign key to EntityA (thats the problem)
An other descendant entity 'BParameter' (sibling of AParameter) should have one more attribute:
which is unfortunetelly a foreign key to EntityB (thats the problem)
The problem is, if I declare the foreign constraint in SQL server for theese foreign keys, LLBLGen designer does not allow to push down foreign key attributes to descendants, it must be defined in the hierachy root.
If I do not define the foreign constraint in database then I am free to push EntityAId to AParameter descendant and push EntityBIdB to BParameter descendant, but I loose the ability to create an EntityA property in AParameter entity in my domain model. (and the inverse AParameters property in EntityA entity.
To generalize this problem in the terms of domain model (maybe I missed something):
Inherited properties can be simple or complex (complex means: Refers to an other entity)
Specific properties, which are introduced by some descendant can be only simple, but no complex, which is a pretty huge limit, regarding a regular domain model.
How to accomplish this task, or is there any workaround?
thx for answers: horo
DDL:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[EntityB]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[EntityB](
[EntityBId] [int] NOT NULL,
[SomeData] varchar NULL,
CONSTRAINT [PK_EntityB] PRIMARY KEY CLUSTERED
(
[EntityBId] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[EntityA]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[EntityA](
[EntityAId] [int] NOT NULL,
[SomeData] varchar NULL,
CONSTRAINT [PK_EntityA] PRIMARY KEY CLUSTERED
(
[EntityAId] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Parameter]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Parameter](
[ParameterId] [int] NOT NULL,
[ParameterType] [int] NOT NULL,
[ParameterValue] varchar NOT NULL,
[EntityAId] [int] NULL,
[EntityBId] [int] NULL,
CONSTRAINT [PK_Parameter] PRIMARY KEY CLUSTERED
(
[ParameterId] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Parameter_EntityA]') AND parent_object_id = OBJECT_ID(N'[dbo].[Parameter]'))
ALTER TABLE [dbo].[Parameter] WITH CHECK ADD CONSTRAINT [FK_Parameter_EntityA] FOREIGN KEY([EntityAId])
REFERENCES [dbo].[EntityA] ([EntityAId])
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Parameter_EntityB]') AND parent_object_id = OBJECT_ID(N'[dbo].[Parameter]'))
ALTER TABLE [dbo].[Parameter] WITH CHECK ADD CONSTRAINT [FK_Parameter_EntityB] FOREIGN KEY([EntityBId])
REFERENCES [dbo].[EntityB] ([EntityBId])