-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ModelBuilder: stackoverflow for may be invalid relationship via fluent api #9478
Comments
Throw in this line in OnModelCreating it ignores the relationship and creates database without FK. |
This worked in 1.1.2 packages creating a self-ref fk. (defining such relationship is possible in SqlServer).
|
Impact: Self-referencing PK-to-PK relationships cause stack overflow. |
This is a big issue for us. Is there any likely release date for 2.0.1? Thanks |
This is also a blocker for us, interested to know the timescales for 2.0.1 too... |
Tentative schedule for this fix is early October, but that could change. |
Waiting a solution too. Tks. |
That had to fail a unit test somewhere! |
I think the tests missed this because a PK-to-PK self referencing relationship doesn't seem to have any point. It always points to itself and can never change. For people hitting this, it would be interesting to know if there is a reason that your databases contain these relationships? |
I don't even have anything that crazy and I'm getting the same error... In my example a person should have a TimeZone associated with them. Here are two tables I have in the DB. CREATE TABLE [dbo].[TimeZone]
(
[TimeZoneId] SMALLINT NOT NULL PRIMARY KEY IDENTITY,
[Code] VARCHAR(5) NOT NULL,
[Name] VARCHAR(150) NOT NULL,
[Description] VARCHAR(150) NOT NULL
)
CREATE TABLE [dbo].[Person] (
[Id] INT NOT NULL,
[FirstName] VARCHAR (50) NULL,
[MiddleName] VARCHAR (50) NULL,
[LastName] VARCHAR (50) NULL,
[PersonPrefixId] SMALLINT NULL,
[Suffix] VARCHAR (20) NULL,
[Title] VARCHAR (50) NULL,
[TimeZoneId] SMALLINT NOT NULL DEFAULT 13,
[AppUserId] UNIQUEIDENTIFIER NULL,
[CreatedByUserId] UNIQUEIDENTIFIER NOT NULL,
[CreatedDate] DATETIME CONSTRAINT [DF_Person_CreatedDate] DEFAULT (getutcdate()) NOT NULL,
[LastModifiedByUserId] UNIQUEIDENTIFIER NOT NULL,
[LastModifiedDate] DATETIME CONSTRAINT [DF_Person_LastModifiedDate] DEFAULT (getutcdate()) NOT NULL,
CONSTRAINT [PK_Person] PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_Person_is_a_Party] FOREIGN KEY ([Id]) REFERENCES [dbo].[Party] ([Id]),
CONSTRAINT [FK_Person_PersonPrefixId] FOREIGN KEY ([PersonPrefixId]) REFERENCES [dbo].[PersonPrefix] ([Id]),
CONSTRAINT [FK_Person_CreatedByUserId] FOREIGN KEY ([CreatedByUserId]) REFERENCES [dbo].[AppUser]([Id]),
CONSTRAINT [FK_Person_LastModifiedByUserId] FOREIGN KEY ([LastModifiedByUserId]) REFERENCES [dbo].[AppUser]([Id]),
CONSTRAINT [FK_Person_AppUserId] FOREIGN KEY ([AppUserId]) REFERENCES [dbo].[AppUser]([Id]),
CONSTRAINT [FK_Person_TimeZoneId] FOREIGN KEY ([TimeZoneId]) REFERENCES [dbo].[TimeZone] ([TimeZoneId]),
) After the database is created from the project.. I use the following scaffolding command to generate my classes. Scaffold-DbContext -Verbose "Server=BLAH;Database=OC;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -Schemas "dbo" -Force Here are the classes that are generated by the scaffolding:
Then, with a simple console application running it breaks on accessing the data.... Exception : System.StackOverflowException In the EF file Annotatable.cs Line 130 Let me know, I'm sure I can put together a smaller example project if you need me to. |
@AndriySvyryd Can you verify the code above is the same root cause and is fixed in 2.0.1? |
@dabasejumper Could you share a repro with a complete model? The original DB schema is not needed. |
Hi @AlanMacdonald, @Nyami, @dabasejumper, @tandradeflorencio. We are gathering information on the use of EF Core pre-release builds. You reported this issue shortly after the release of 2.0.0 RTM. It would be really helpful if you could let us know:
Thanks in advance for any feedback. Hopefully this will help us to increase the value of pre-release builds going forward. |
Workaround: If you are scaffolding from an existing database you can use the query from #9462 (comment) to find the redundant FKs that cause this issue. Then either drop them or comment out the corresponding navigation properties. |
@AndriySvyryd @ajcvickers I could not reproduce this issue with a simple two table solution. I tried last night. It wasn't even an issue with the EF/Linq query that I was trying to execute. It was further down the model. So sql from #9462 (comment) fixed my issue. It was NOT with the two tables I was looking it. It unveiled a typo that I had made in one of the table designers of in my DB project. It was as described above... A self referencing FK.... Was supposed to be DataLoadBatch instead of just DataLoad :) Thank you for your feedback helping me thru this issue... Although, this issue probably needs a better error message when it is encountered. Thanks for everything... Mike |
This patch bug is approved for the 2.0.x patch. Please send a PR to the |
Hi, we have a public test feed that you can use to try out the ASP.NET/EF Core 2.0.3 patch! To try out the pre-release patch, please refer to the following guide:
We are looking for feedback on this patch. We'd like to know if you have any issues with this patch by updating your apps and libraries to the latest packages and seeing if it fixes the issues you've had, or if it introduces any new issues. If you have any issues or questions, please reply on this issue to let us know as soon as possible. Thanks, |
Model
Watch it 🔥
The text was updated successfully, but these errors were encountered: