Reverse Engineer with option "UseDbContextSplitting": true gives compiler error on generated code
See original GitHub issueUsing VS2022 og reverse engineer with target "EF Core 6 (preview) and checking option “Split DbContext into Configuration classes” - then the generated code gives compiler error. There is a mixup in which generated code for Configuration class is written to the DbContext class. My generated code fails on:
DbContext - OnModelCreating():
modelBuilder.ApplyConfiguration(new Configurations.TableNameConfiguration());
}); // Does not belong here
}); // Does not belong here
OnModelCreatingPartial(modelBuilder);
And in the corresponding TableConfigurationClass
entity.HasMany(d => d.ServiceParameter)
.WithMany(p => p.ProfileParameter)
.UsingEntity<Dictionary<string, object>>(
"ParameterConnection",
l => l.HasOne<ServiceParameter>().WithMany().HasForeignKey("ServiceParameterId").OnDelete(DeleteBehavior.ClientSetNull).HasConstraintName("FK_ParameterConnection_ServiceParameterDefinition"),
r => r.HasOne<ProfileParameter>().WithMany().HasForeignKey("ProfileParameterId").HasConstraintName("FK_ParameterConnection_ProfileParameterDefinition"),
j =>
{
j.HasKey("ProfileParameterId", "ServiceParameterId");
j.ToTable("ParameterConnection");
j.HasIndex(new[] { "ServiceParameterId" }, "IX_ParameterConnection_ServiceParameterId");
OnConfigurePartial(entity);
In my project this happens on 2 Configuration classes - hence 2 * " });" on DbContext class. This is likely connected to Foreign key or Index definitions.
Correct code should be:
j =>
{
j.HasKey("ProfileParameterId", "ServiceParameterId");
j.ToTable("ParameterConnection");
j.HasIndex(new[] { "ServiceParameterId" }, "IX_ParameterConnection_ServiceParameterId");
}); // Missing in code file - written in DbContext.OnModelCreating method.
OnConfigurePartial(entity);
}
Steps to reproduce
Further technical details
EF Core Power Tools version: 2.5.774.0
Database engine: SQL Server
Visual Studio version: Visual Studio 2022 Preview 4.1
Issue Analytics
- State:
- Created 2 years ago
- Comments:16 (10 by maintainers)
Top Results From Across the Web
EF Core 7 Reverse Engineer Error · Issue #1523
Error when reverse engineering a model from an existing DB: Microsoft SQL Server 2014 12.0.6439.10 (X64) using EFCore 7 RC1 System.
Read more >How do I reverse engineer a compiler?
My inclination would be to disassemble the compiler. If it's written in .NET (C#, VB.NET, etc.) or Java, there are decompilers that will ......
Read more >Can you "stop" a C program from being reverse engineered?
The real question is, how easy is it to reverse engineer? C is trivial to decompile; I've seen some surprisingly clean C code...
Read more >EFCorePowerTools
Trying to "Compare DB Context to database" is giving me an error shown below. I have also had issues in the past doing...
Read more >Strategy for reverse engineering legacy C code (C code)
This topic provides a roadmap to ease the process of reverse engineering legacy code using C Code Reverser, aimed at first time users...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I am working on a non regex based solution.
@ErikEJ yes, works fine for me now 👍