EFCorePowerTools: Reverse Engineer with option "UseDbContextSplitting": true gives compiler error on generated code
Using 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
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 16 (10 by maintainers)
I am working on a non regex based solution.
@ErikEJ yes, works fine for me now 👍
What regex(es) do you need assist with? Post them up so we can take a look…
I think a code based solution is better and more maintainable, let me look into that over the next few days.