-
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
dotnet ef dbcontext optimize failing with HasTrigger modifer on ToTable #32364
Comments
/cc @AndriySvyryd |
@kev160967 Could you create a small repro project? Just the snippet you posted above is not enough to trigger this error. |
Thanks @AndriySvyryd . I've just put together a simple model example, and it works flawlessly. Clearly it must be something else in my model, but I'm not sure where yet and will need to do a bit more investigating. I've just commented out all of the HasTrigger actions and the compiled model builds with no issues. I then added a single one back in and again I'm getting the dictionary error. I'll investigate further in the morning, but any suggestions would be welcome! Looking at the code I'd guess that it's failing on line 418:
Perhaps I can narrow it down a bit by tracking through the code around this, to see if anything in my model might be triggering something related |
Do you use any plugins, like EFCore.NamingConventions? |
No, totally vanilla. This model was originally an ObjectContext/edmx based one. When I migrated the projects to net6 I wrote a translator to convert the edmx to fluent/code first, so pretty much everything is explicit. I've a meeting this morning, but afterwards my plan is to download the tooling locally and dig into what's going on. It's likely something weird about my model, but I'll report back here what I find, in case its useful |
I'm struggling a little. I've built the project using build.cmd and opened it in VS2022 by dropping EFCore.sln on to startvs.cmd. I set up a debug launch profile to run dbcontext optimize on my test project. Initially it complained it couldn't find EF.DLL
I could see three instance of ef.dll under attifacts, so tried copying the one from artifacts\bin\ef\Debug\netcoreapp2.0 to the location it was looking. This appeared to work, in as much as the command now completed and gave me the expected error, but I feel I may have missed something to need to do this? I tried instrumenting the code in RelationalCSharpRuntimeAnnotationCodeGenerator, and debugging, but nothing seemed to make any difference. As a test I tried renaming the class, rebuilding again (both from VS and from build.cmd) and running again, but the error stack trace indicates that my version of the code was not being run, as the class name remained unchanged. Can you suggest what I might be missing? |
@kev160967 Provide code for a runnable console app that reproduces the issue.. |
@ErikEJ Currently the only code I have that I can reproduce this on is the initial model I got the error on. I've taken a test copy of it, removed dependencies and trimmed off pieces here and there, and am still getting the error, and don't have any thoughts on what to remove next, short of trimming out entities until the error goes away. There are a lot of relationships though, and a lot of entities, so this isn't particularly simple. I could supply the resulting project (it's a library rather than a console app) but wouldn't want to post it in an open thread - happy to send to someone directly though? |
Okay, I've reproduced the issue with a small project. To be honest, it looks fairly innocuous? One base type with two types inheriting from it. Attached zip file contains the project To reproduce the issue I ran the following command within the project directory: dotnet ef dbcontext optimize -o Model\Compiled -n Saturn.Data.Model.Compiled --context Saturn.Data.Model.SaturnEntities and here's the output:
|
Looks like it could be the inverse of this? That dictates adding HasTrigger only to the base class. If I do that I still get the error, but if I turn it around and add it to the derived classes I no longer get the error. I'm currently going through my original model adding in triggers and testing the model. I'll report back when I'm done Interestingly this doesn't seem to be an issue until you have more than one inheriting entity? |
Also I've just see this which sounds like it should be an alternative way to resolve my issue |
Duplicate of #31627 |
I am upgrading an EF6 project that uses a compiled model to EF8. When running the dbcontext optimize command I got an error that "The given key 'EntityType: ContainerService' was not present in the dictionary", ContainerService being one of the entities in my model. I narrowed the cause down to the ContainerService entity having a HasTrigger modifier:
I confirmed this by removing the HasTrigger, at which point the error moved to the next entity that had HasTrigger set.
This is the reported stack trace
This is the tool output - there's a lot of it, so I have removed messages about explicit relationships, etc
Include provider and version information
EF Core version: 8.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: NET 8.0
Operating system: Windows 11 Pro x64
IDE: Visual Studio 2022 17.8.0
The text was updated successfully, but these errors were encountered: