Help with circular relationship.

Posts   
 
    
Jamison avatar
Jamison
User
Posts: 14
Joined: 22-Dec-2006
# Posted on: 18-May-2007 23:39:54   

Hi,

I am just getting started, and I have already hit a bit snag. My datamodel has a circular relationship where a Customer can be subtyped to a Partner but then a Customer can belong to a Partner (it's nullable).

The code generates and compiles, but my PartnerEntity is throwing up these kind of errors:

Warning 1 function 'GetRelationInfoCustomer' shadows an overridable method in the base class 'CustomerEntity'. To override the base method, this method must be declared 'Overrides'.

and

Warning 2 function 'GetRelationInfoAccountTypeCollectionViaCustomer' shadows an overridable method in the base class 'CustomerEntity'. To override the base method, this method must be declared 'Overrides'.

Here are the interesting bits of the datamodel: ((DDL code edited on May 21st. Sorry I was playing around with a new program to generate the previous code))




Create table [Customer]
(
    [CustID] Integer Identity(10000,1) NOT NULL,
    [PartnerID] Integer NULL,
    [AccountType] Nvarchar(20) NOT NULL,
Constraint [PK_Customer_CustID] Primary Key ([CustID])
) 
go

Create table [AccountType]
(
    [AccountType] Nvarchar(20) NOT NULL,
    [Description] Nvarchar(100) NOT NULL,
    [OrderBy] Integer NOT NULL,
Constraint [PK_AccountType_AccountType] Primary Key ([AccountType])
) 
go

Create table [Partner]
(
    [PartnerID] Integer NOT NULL,
Constraint [PK_Partner_PartnerID] Primary Key ([PartnerID])
) 
go


Alter table [Partner] add Constraint [FK_Customer_Partner_PartnerID] foreign key([PartnerID]) references [Customer] ([CustID])  on update no action on delete no action 
go
Alter table [Customer] add Constraint [FK_AccountType_Customer_AccountType] foreign key([AccountType]) references [AccountType] ([AccountType])  on update no action on delete no action 
go
Alter table [Customer] add Constraint [FK_Partner_Customer_PartnerID] foreign key([PartnerID]) references [Partner] ([PartnerID])  on update no action on delete no action 
go



I am using LLBLGenPro Version 2.0.0.0 Final Released on March 21st, 2007. The database is SQL Server 2000. I am generating .Net 2.0 VB code.

Thanks, Jamison

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 21-May-2007 07:28:51   

Jamison, Do you have define an LLBLGenPro hierarchy at LLBLGenPro Designer? What template set are you using (Adapter || SS)?

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 21-May-2007 11:04:58   

A cycle in a relational model is often a big problem, as it creates a broken FK constraint: you have to work around the FK constraint to get the data inserted which makes it ineffective.

I can't even create the tables in one go with the DDL you posted simple_smile , which is often a sign something should be modelled differently. However, as a customer won't refer to the partner which is its subtype part, thus always to a different partner, it won't be a problem at runtime.

That said, I can't reproduce it. When I use your table DDL and create it in a couple of steps, I create entities, Customer and Partner, created the hierarchy, renamed PartnerId in Partner to CustId so it overrides the proper field and then generated VB.NET .NET 2.0 adapter code and it compiles OK.

(btw, IMHO this thread belongs in generated code forum, I'll leave it here for now, though we monitor the architecture forum with a slightly less higher priority, so errors / issues etc. shouldn't be discussed in the architecture forum but in the other forums so your question gets the highest priority simple_smile I'll move your thread in our support queues to the highest priority)

Frans Bouma | Lead developer LLBLGen Pro
Jamison avatar
Jamison
User
Posts: 14
Joined: 22-Dec-2006
# Posted on: 21-May-2007 16:13:03   

Hi,

Thank you for the weekend response.

daelmo, I am using adapter. I have defined Partner as a subtype of Customer.

Otis, I'm sorry about the bad DDL (the OP is updated). I was playing with a new toy wink . I generally create the tables and FKs in seperate statements. The cycle works because the Customer.PartnerID is nullable.

Otis, I will try your renaming suggestion.

I have three cycle relationships in my data model. Is a third table the preferred way of cleaning up cycles? Something like this:


Create table [Customer]
(
    [CustID] Integer Identity(10000,1) NOT NULL,
    [AccountType] Nvarchar(20) NOT NULL,
Constraint [PK_Customer_CustID] Primary Key ([CustID])
) 
go

Create table [Partner]
(
    [PartnerID] Integer NOT NULL,
Constraint [PK_Partner_PartnerID] Primary Key ([PartnerID])
) 
go

Create table [PartnerCustomer]
(
    [CustID] Integer NOT NULL,
    [PartnerID] Integer NOT NULL,
Constraint [PK_PartnerCustomer_CustID] Primary Key ([CustID])
) 
go

Create table [AccountType]
(
    [AccountType] Nvarchar(20) NOT NULL,
    [Description] Nvarchar(100) NOT NULL,
    [OrderBy] Integer NOT NULL,
Constraint [PK_AccountType_AccountType] Primary Key ([AccountType])
) 
go

Alter table [Partner] add Constraint [FK_Customer_Partner_PartnerID] foreign key([PartnerID]) references [Customer] ([CustID])  on update no action on delete no action 
go

Alter table [Customer] add Constraint [FK_AccountType_Customer_AccountType] foreign key([AccountType]) references [AccountType] ([AccountType])  on update no action on delete no action 
go

Alter table [PartnerCustomer] add Constraint [FK_Partner_PartnerCustomer_PartnerID] foreign key([PartnerID]) references [Partner] ([PartnerID])  on update no action on delete no action 
go

Alter table [PartnerCustomer] add Constraint [FK_Customer_PartnerCustomer_CustID] foreign key([CustID]) references [Customer] ([CustID])  on update no action on delete no action 
go

(Bah, I forgot a table and had to edit the code after posting. disappointed )

jbb avatar
jbb
User
Posts: 267
Joined: 29-Nov-2005
# Posted on: 21-May-2007 16:41:52   

Hello,

do you really need inheritance for your example? With a relation table like in your last post, you can link a customer to another using a partnerId like an FK. Did you had the time to try the rename that Otis ask you?

Jamison avatar
Jamison
User
Posts: 14
Joined: 22-Dec-2006
# Posted on: 21-May-2007 17:17:01   

jbb wrote:

do you really need inheritance for your example? With a relation table like in your last post, you can link a customer to another using a partnerId like an FK. Did you had the time to try the rename that Otis ask you?

Hi jbb,

I'm not sure I 100% understand you. In this app it seems a Partner is definitely a sub-type of Customer. All the contact and billing information is related to the Customer. The Partner defines extra settings and functionality.

Have not tried the rename yet. I'm upgrading an existing system, so that will definitely get messy. It might actually be easier to move the relationhip to the third table instead of renaming.

Jamison

Jamison avatar
Jamison
User
Posts: 14
Joined: 22-Dec-2006
# Posted on: 21-May-2007 23:17:24   

Otis, I tried renaming the columns, but it still generated tons of warnings. I'm going to try inserting a 3rd table.


'ARBO.ORM.EntityClasses.PartnerEntity.GetRelationInfoCustomer()' hides inherited member '.ARBO.ORM.EntityClasses.CustomerEntity.GetRelationInfoCustomer()'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.

This is the table structure used


Create table [Customer]
(
    [CustID] Integer Identity(10000,1) NOT NULL,
    [PartnerID] Integer NULL,
Constraint [PK_Customer_CustID] Primary Key ([CustID])
) 
go

Create table [Partner]
(
    [CustID] Integer NOT NULL,
Constraint [PK_Partner_CustID] Primary Key ([CustID])
) 
go

Alter table [Partner] add Constraint [FK_Customer_Partner_CustID] foreign key([CustID]) references [Customer] ([CustID])  on update no action on delete no action 
go
Alter table [Customer] add Constraint [FK_Partner_Customer_PartnerID] foreign key([PartnerID]) references [Partner] ([CustID])  on update no action on delete no action 
go

Jamison

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 22-May-2007 09:42:12   

If Partner is a SubType of Customer.

Then I think the following should be the model:

Create table [Customer]
(
    [CustID] Integer Identity(10000,1) NOT NULL,
    [PartnerID] Integer NULL,
Constraint [PK_Customer_CustID] Primary Key ([CustID])
) 
go

Create table [Partner]
(
    [CustID] Integer NOT NULL,
Constraint [PK_Partner_CustID] Primary Key ([CustID])
) 
go

Alter table [Partner] add Constraint [FK_Customer_Partner_CustID] foreign key([CustID]) references [Customer] ([CustID]) on update no action on delete no action 
go
Alter table [Customer] add Constraint [FK_Partner_Customer_PartnerID] foreign key([PartnerID]) references [Customer] ([CustID]) on update no action on delete no action 
go

Where Customer.PartnerID references Customer.CustID (Self Referencing relation)

Jamison avatar
Jamison
User
Posts: 14
Joined: 22-Dec-2006
# Posted on: 22-May-2007 16:27:37   

Hi Walaa,

That seems to work. It's not exactly what I intended, but it's close enough for government work wink Thanks for all the help guys.

Jamison