Answer the question
In order to leave comments, you need to log in
Why does Entity Framework create new keys?
Hello.
Created a database in visual and (db.mdf), created connection tables and even filled the database with test records.
Now you need to connect the Entity Framework. I create a model (ADO.NET Entity Data Model), I generate it according to my database. Everything is going well.
After starting the application, it creates a database similar to me in SQL Server, saves it to the user's documents on the computer. But here's what's strange in every table where there were foreign keys, another one was created and the links are tied to them.
For example
it was:
[Id] INT IDENTITY (1, 1) NOT NULL,
[FirstName] NVARCHAR (50) NOT NULL,
[SecondName] NVARCHAR (50) NOT NULL,
[PositionId] INT NOT NULL,
[GroupId] INT NOT NULL,
CONSTRAINT [PK_Employees] PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_Employees_Group] FOREIGN KEY ([GroupId]) REFERENCES [dbo].[Groups] ([Id]),
CONSTRAINT [FK_Employees_Position] FOREIGN KEY ([PositionId]) REFERENCES [dbo].[Positions] ([Id])
[Id] INT IDENTITY (1, 1) NOT NULL,
[FirstName] NVARCHAR (MAX) NULL,
[SecondName] NVARCHAR (MAX) NULL,
[PositionId] INT NOT NULL,
[GroupId] INT NOT NULL,
[Positions_Id] INT NULL,
[Groups_Id] INT NULL,
CONSTRAINT [PK_dbo.Employees] PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_dbo.Employees_dbo.Groups_Groups_Id] FOREIGN KEY ([Groups_Id]) REFERENCES [dbo].[Groups] ([Id]),
CONSTRAINT [FK_dbo.Employees_dbo.Positions_Positions_Id] FOREIGN KEY ([Positions_Id) REFERENCES [dbo].[Positions] ([Id])
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question