EFDesigner2022 icon indicating copy to clipboard operation
EFDesigner2022 copied to clipboard

Dbcontext generated for EFDesigner 2022 now include .UseTpcMappingStrategy() for all tables

Open rdeharo opened this issue 11 months ago • 2 comments

EF Core 8 latest with postgresql

When I change the model and save changes, dbcontext generated for EFDesigner 2022 now include .UseTpcMappingStrategy() for all tables. So when I generate the migration for update the database the migration code include:

        migrationBuilder.CreateSequence(
            name: "TableNameSequence",
            schema: "public");

for each PK of all tables.

Then a new sequence will be created for each pk of each table. But the sequence of each pk of each table already exists with the name SequenceFieldName

How can I disable this behavior?

rdeharo avatar Mar 01 '24 07:03 rdeharo

I have a similar problem with this. I had an older version of EFDesigner, and my extension updated itself. I'm currently on version 4.2.6.3 of EFDesigner. However, my code base is using EFCore 6.0.27 and .Net 6. But now, when code auto generates, it adds "UseTpcMappingStrategy" to all my tables. And this shows up as "does not contain a definition for UseTcpMappingStrategy". I tried ensuring that my EFModel has the settings for Entity Framework Version = EFCore and Entity Framework Package Version = 6.0.27.

I haven't done anything except update the EF Designer extension. Inheritance Strategy = "TablePerHierachy". I'll have to revert back to the older extension to continue using this. Was hoping it was a simple configuration I could do to keep it generating compatible code for .Net 6 & EFCore 6.0.27. I am using EF for SqlServer.

<TargetFramework>net6.0</TargetFramework>

<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.27" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.27">
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="6.0.27" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.27" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.27">

Generated Context in OnModelCreating example below;

     modelBuilder.Entity<global::EnergyNet.Database.EF.Models.SendEmail.Entities.EmailType>()
                 .**UseTpcMappingStrategy**().ToTable("EmailType")
                 .HasKey(t => t.Id);
     modelBuilder.Entity<global::EnergyNet.Database.EF.Models.SendEmail.Entities.EmailType>()
                 .Property(t => t.Id)
                 .ValueGeneratedNever()
                 .IsRequired();
     modelBuilder.Entity<global::EnergyNet.Database.EF.Models.SendEmail.Entities.EmailType>()
                 .Property(t => t.Name)
                 .HasMaxLength(64)
                 .IsRequired();
     modelBuilder.Entity<global::EnergyNet.Database.EF.Models.SendEmail.Entities.EmailType>().HasIndex(t => t.Name)
                 .IsUnique();
     modelBuilder.Entity<global::EnergyNet.Database.EF.Models.SendEmail.Entities.EmailType>()
                 .Property(t => t.Display)
                 .HasMaxLength(64);
     modelBuilder.Entity<global::EnergyNet.Database.EF.Models.SendEmail.Entities.EmailType>()
                 .HasMany<global::EnergyNet.Database.EF.Models.SendEmail.Entities.EmailTemplate>(p => p.EmailTemplates)
                 .WithOne(p => p.EmailType)
                 .HasForeignKey("EmailTypeId")
                 .IsRequired();
                 
                 

Any suggestions would be greater appreciated. Reverting the extension back to 4.2.5.1 fixes this behavior for me.

Relki avatar Mar 09 '24 05:03 Relki

Yes I'm getting this exact same issue; but I'm using EfCore 6. Haven't at all touched the model file, just updated the extension to 4.2.7.

Doing a bit of digging, the UseTpcMappingStrategy and related extension methods were introduced for EFCore 7 and 8.

With my library, I'm getting compile time errors as those extension methods don't exist for EFCore6. Generating these extension methods should be disabled for EFCore6 and earlier.

mamift avatar Apr 10 '24 22:04 mamift