Foreign key relationships mismatching when updating model from database

2 posts, 0 answers
  1. Trevor
    Trevor avatar
    5 posts
    Member since:
    Jul 2011

    Posted 06 Jun 2012 Link to this post

    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.


  2. Ady
    Admin
    Ady avatar
    589 posts

    Posted 11 Jun 2012 Link to this post

    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!
  3. DevCraft banner
Back to Top