ErikEJ / EFCorePowerTools

Entity Framework Core Power Tools - reverse engineering, migrations and model visualization in Visual Studio & CLI
MIT License
2.19k stars 298 forks source link

EFCorePowerTools Not seeing dependencies #143

Closed tburger closed 5 years ago

tburger commented 5 years ago

Describe what is not working as expected. I have a SQL table with several FK dependencies to other tables. Many of them show up fine but a few do not show. They do not show in the SSMS show dependencies tool AND are not being picked up by EFCorePowerTools BUT they do show when I run the following: EXEC sp_MSdependencies N'Item.Item', null, 1053183 . I can not figure out anything that is different about these FK relationships and the ones that work.

Steps to reproduce

Include a complete description that I can redo to reproduce the issue. Maybe if I understood what sql command that EFCorePowerTools is using to reverse engineer the Dependencies, I could figure out how these FK relationships are different than others. I have looked at size of table name and size of FK relationship name... it is nothing obvious

Further technical details

EF Core Power Tools version: (found in About dialog - blue questionmark icon on context menu) Version 1.0667 Database engine: (SQlite, SQL Compact, SQL Server, Postgres) SQL Server 2017 Enterprise Visual Studio version: (e.g. Visual Studio 2017 15.7) Visual Studio 2017

ErikEJ commented 5 years ago

Hi, the SQL command to get the foreign keys is available here: https://github.com/aspnet/EntityFrameworkCore/blob/master/src/EFCore.SqlServer/Scaffolding/Internal/SqlServerDatabaseModelFactory.cs#L900

tburger commented 5 years ago

Thank you. I thought I was on a role with that but then I realized that is only the depends on not the things that depend on it. My problem is that EFCorePowerTools is not making a relationship from item to 3 different tables that have a foreign key but it does for that are defined the same way. The same problem that is causing EFCorePowerTools to not map it also seems to show up in SSMS.

The SSMS also does not show the relationship back so that is the easiest way for me to describe the issue: Here you will see that PurchaseOrderDetailHistory depends on Item [cid:image002.jpg@01D48F40.53CEAEC0]

So Item should show that PurchaseOrderDetailHistory has a dependency on it [cid:image004.png@01D48F40.0CCA9930]

From: Erik Ejlskov Jensen notifications@github.com Sent: Saturday, December 8, 2018 7:19 AM To: ErikEJ/EFCorePowerTools EFCorePowerTools@noreply.github.com Cc: Teresa Burger t.burger@live.com; Author author@noreply.github.com Subject: Re: [ErikEJ/EFCorePowerTools] EFCorePowerTools Not seeing dependencies (#143)

Hi, the SQL command to get the foreign keys is available here: https://github.com/aspnet/EntityFrameworkCore/blob/master/src/EFCore.SqlServer/Scaffolding/Internal/SqlServerDatabaseModelFactory.cs#L900

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/ErikEJ/EFCorePowerTools/issues/143#issuecomment-445458674, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AAmZcYCoaHXQyRaIseJWC5AKHNtXoOyrks5u27xegaJpZM4ZI68Q.

ErikEJ commented 5 years ago

I cannot see any images, you need to upload on Github web site. But it would be much better with a script to create your schema...

tburger commented 5 years ago

Attached are both images and a script to recreate the db schema. You will need to create a new db then run the script to create the tables and relationships.

testdb.txt sql1 sql2 jpg

tburger commented 5 years ago

Here is a pic of what comes up with EXEC sp_MSdependencies N'Item.Item', null, 1053183 All of the highlighted tables are not showing up in the Gui as dependent on Item. I assume this also means they are not mapping in EFCorePowerTools Reverse engineering. I only know the PurchaseOrderDetailHistory is not. The db is still changing frequently so we are regenerating often.

tawx5

ErikEJ commented 5 years ago

Not sure how sp_depends and SSMS interperts "depends", but the EF Core Power Tools requires a FK to be defined - what I am saying is that looking for dependencies that are missing in the UI is an issue that does not belong here.

The results from the sql query I linked to are much more interesting!

ErikEJ commented 5 years ago

Thanks for the sample database. I do not understand what your exact issue actually is!

any of them show up fine but a few do not show.

Show up where?

are not being picked up by EFCorePowerTools

What does "not being picked up" mean?

tburger commented 5 years ago

My apologies.. This all started over PurchaseOrderDetailHistories not being added to the Item model when EFCorePowerTools was used to generate the model. I used the SQL gui to show her what she was missing in her check and she showed me that it was not being generated and thus why she couldn't do what I showed. Some how in all of this, either I never tried it on my box or I have shook a tree loose and it is working for me. I will check with her tomorrow and see if it works for her also now or we can isolate that problem. I am sorry for waisting your time.

ErikEJ commented 5 years ago

No worries, glad you got it sorted.