Skip to content
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

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

Open
rdeharo opened this issue Mar 1, 2024 · 3 comments

Comments

@rdeharo
Copy link

rdeharo commented Mar 1, 2024

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?

@Relki
Copy link

Relki commented Mar 9, 2024

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.

@mamift
Copy link

mamift commented Apr 10, 2024

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.

@mciprijanovic
Copy link

I have the same issue so I have to revert to older extension version. If I set TPT as default inheritance strategy in the designer, .UseTpcMappingStrategy().ToTable() is generated for every table and makes mi troubles since I use TPT inheritance. If I delete this .UseTpcMappingStrategy(). everything will wotk, but as soon as I change anything in the designer, code returns which is normal... Please consider this as a bug with priority.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants