Reference to a table that is TPT (always update)

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
ruda
Posts: 17
Joined: Sat 29 Mar 2014 17:10

Reference to a table that is TPT (always update)

Post by ruda » Mon 09 May 2022 13:43

Version: 6.12.1419

I detected a problem, to occur was like this:

Code: Select all

CREATE DATABASE TestED
GO

USE [TestED]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Animal](
	[AnimalId] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](50) NOT NULL,
 CONSTRAINT [PK_Animal] PRIMARY KEY CLUSTERED 
(
	[AnimalId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Cat](
	[AnimalId] [int] NOT NULL,
	[FieldB] [int] NOT NULL,
 CONSTRAINT [PK_Cat] PRIMARY KEY CLUSTERED 
(
	[AnimalId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Dog](
	[AnimalId] [INT] NOT NULL,
	[Field1] [NVARCHAR](10) NOT NULL,
 CONSTRAINT [PK_Dog] PRIMARY KEY CLUSTERED 
(
	[AnimalId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[TestRef](
	[TestRefId] [INT] IDENTITY(1,1) NOT NULL,
	[TesAB] [NVARCHAR](50) NOT NULL,
	[AnimalId_Dog] [INT] NOT NULL,
 CONSTRAINT [PK_TestRef] PRIMARY KEY CLUSTERED 
(
	[TestRefId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[Cat]  WITH CHECK ADD  CONSTRAINT [FK_Cat_Animal] FOREIGN KEY([AnimalId])
REFERENCES [dbo].[Animal] ([AnimalId])
ON DELETE CASCADE
GO

ALTER TABLE [dbo].[Cat] CHECK CONSTRAINT [FK_Cat_Animal]
GO

ALTER TABLE [dbo].[Dog]  WITH CHECK ADD  CONSTRAINT [FK_Dog_Animal] FOREIGN KEY([AnimalId])
REFERENCES [dbo].[Animal] ([AnimalId])
ON DELETE CASCADE
GO

ALTER TABLE [dbo].[Dog] CHECK CONSTRAINT [FK_Dog_Animal]
GO

ALTER TABLE [dbo].[TestRef]  WITH CHECK ADD  CONSTRAINT [FK_TestRef_Dog] FOREIGN KEY([AnimalId_Dog])
REFERENCES [dbo].[Dog] ([AnimalId])
GO

ALTER TABLE [dbo].[TestRef] CHECK CONSTRAINT [FK_TestRef_Dog]
GO
I add the first 3 tables for me to create the TPT
Looking like this:

Image Image Image Image

I find a bug here as I create the TPT and then remove the references to the Animal table it doesn't update the diagram, because the AnimalId fields are still visible. But if I save and then reopen the model it disappears.
But something that does not impact. But I spent a few hours thinking I was doing something wrong.

Then I add another TableRef table to the model.

With that it does not create the reference to the Dog table.
And it stays in the update loop.

Image Image

If I add all the tables before creating the TPT it adds the reference correctly.
But it stays in the update loop too.

Image

DmitryGm
Devart Team
Posts: 152
Joined: Fri 11 Dec 2020 10:27

Re: Reference to a table that is TPT (always update)

Post by DmitryGm » Wed 11 May 2022 19:13

Please clarify:

1.) The type of the Model you create

2.) How did you remove the references? Remove from the database? From the diagram in the Entity Developer?

3.) How did you update the diagram after removing references?

Describe your actions in detail and step by step.

ruda
Posts: 17
Joined: Sat 29 Mar 2014 17:10

Re: Reference to a table that is TPT (always update)

Post by ruda » Wed 11 May 2022 21:23

1. EF Core
2. It is not removed. the Entity Developer that does not create.
3. Yes

DmitryGm
Devart Team
Posts: 152
Joined: Fri 11 Dec 2020 10:27

Re: Reference to a table that is TPT (always update)

Post by DmitryGm » Thu 12 May 2022 15:09

ruda wrote: Wed 11 May 2022 21:23 1. EF Core
2. It is not removed. the Entity Developer that does not create.
That is EF Core Model I Created:

Image

As I can see, the references were created.

ruda
Posts: 17
Joined: Sat 29 Mar 2014 17:10

Re: Reference to a table that is TPT (always update)

Post by ruda » Thu 12 May 2022 15:13

The issue at hand is the TestRef table reference with Dog.
The TPT is created correctly.

DmitryGm
Devart Team
Posts: 152
Joined: Fri 11 Dec 2020 10:27

Re: Reference to a table that is TPT (always update)

Post by DmitryGm » Fri 13 May 2022 11:18

To add the new references you should update model from database with the option "recreate model".

Image
Image
Image
Image
Image
Image
Image

ruda
Posts: 17
Joined: Sat 29 Mar 2014 17:10

Re: Reference to a table that is TPT (always update)

Post by ruda » Fri 13 May 2022 11:47

The solution presented does not make sense.
It's creating a new model.
I lose all the renamed properties, all the created TPTs…
A production project with more than 500 tables is unfeasible.

The problem remains.
Rebuild model is not intended to resolve update issues.

DmitryGm
Devart Team
Posts: 152
Joined: Fri 11 Dec 2020 10:27

Re: Reference to a table that is TPT (always update)

Post by DmitryGm » Mon 16 May 2022 07:09

We have reproduced the issue of updating EF Core Model and the investigation is in progress. We shall inform you as soon as we have any results.

Post Reply