This is a migrated thread and some comments may be shown as answers.

Foreign key relationships mismatching when updating model from database

1 Answer 53 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Trevor
Top achievements
Rank 1
Trevor asked on 06 Jun 2012, 02:57 PM
Hi,

I hope someone might be able to shed some light on this. I added 2 tables to my database, setup their primary keys (exactly the same for both) and setup the foreign key relationships based on those primary keys.

CREATE TABLE [dbo].[TestA](
    [PrimaryKey] [nvarchar](2) NOT NULL,
    [PrimaryKeyTwo] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_TestA] PRIMARY KEY CLUSTERED
(
    [PrimaryKey] ASC,
    [PrimaryKeyTwo] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

CREATE TABLE [dbo].[TestB](
    [PrimaryKey] [nvarchar](2) NOT NULL,
    [PrimaryKeyTwo] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_TestB] PRIMARY KEY CLUSTERED
(
    [PrimaryKey] ASC,
    [PrimaryKeyTwo] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
 
GO
 
ALTER TABLE [dbo].[TestB]  WITH CHECK ADD  CONSTRAINT [FK_TestB_TestA] FOREIGN KEY([PrimaryKey], [PrimaryKeyTwo])
REFERENCES [dbo].[TestA] ([PrimaryKey], [PrimaryKeyTwo])
GO
 
ALTER TABLE [dbo].[TestB] CHECK CONSTRAINT [FK_TestB_TestA]
GO

In SQL management studio it reflects correctly but as soon as I use the entity model to update from the database it goes and mismatch the foreign key relations as follows:

PrimaryKey -> PrimaryKeyTwo
PrimaryKeyTwo -> PrimaryKey

This ultimately results in errors which needs to be manually corrected.

Why would this mismatch occur since both variables are distinctly different.


1 Answer, 1 is accepted

Sort by
0
Ady
Telerik team
answered on 11 Jun 2012, 11:04 AM
Hi Trevor,

 I was able to reproduce this behavior. We will fix this for the next service pack. At the moment you would need to manually fix the mapping in the association editor.
I am sorry for the inconvenience caused.

Your Telerik points have been updated.

Kind regards,
Ady
the Telerik team
Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
Tags
General Discussions
Asked by
Trevor
Top achievements
Rank 1
Answers by
Ady
Telerik team
Share this question
or