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

"Oops!" Problem with TPC, TPT and BulkSynchronize #529

Open
alex-cooke opened this issue Apr 25, 2023 · 4 comments
Open

"Oops!" Problem with TPC, TPT and BulkSynchronize #529

alex-cooke opened this issue Apr 25, 2023 · 4 comments
Assignees

Comments

@alex-cooke
Copy link

Description

I'm struggling to get BulkSynchronize to work in a simple TPC scenario in EFCore 7. Do you have a sample of a TPC or TPT scenario you can share?

Exception

The specific error I am seeing is:

Oops! The BulkSynchronize is not compatible with TPH, TPT and TPC when the same property name is mapped more than once in different entity type.

Code to reproduce the error

using Microsoft.EntityFrameworkCore;

namespace ZzzInheritance.Tests
{
    [TestClass]
    public class CreateAnimal
    {
        [TestMethod]
        public void CreatesAnimal()
        {
            using (var context = new ZooContext())
            {
                //context.Add(new Fish());
                //context.Add(new Bird());
                //context.SaveChanges();

                List<Animal> animals = new();
                animals.Add(new Fish());
                animals.Add(new Bird());
                context.BulkSynchronize(animals);

            }
        }
    }
    public class ZooContext : DbContext
    {
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseSqlServer("Server=.;Database=Workshop;Trusted_Connection=True;TrustServerCertificate=True;");
            base.OnConfiguring(optionsBuilder);
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Animal>().UseTpcMappingStrategy();
            modelBuilder.Entity<Fish>().ToTable("Fish");
            modelBuilder.Entity<Bird>().ToTable("Bird");

            base.OnModelCreating(modelBuilder);
        }
    }

    public abstract class Animal
    {
        public Guid Id { get; set; } = Guid.NewGuid();
    }

    public class Bird : Animal
    {
        public bool CanFly { get; set; } = false;
    }

    public class Fish : Animal
    {
        public bool IsFreshWater { get; set; } = true;
    }
}

Further technical details

  • EF version: 7.0.5
  • EF Extensions version: 7.21.0
  • Database Provider: SQL Server (also fails with Sqlite)

Many thanks in advance!

@JonathanMagnan JonathanMagnan self-assigned this Apr 25, 2023
@JonathanMagnan
Copy link
Member

Hello @alex-cooke ,

Thank you for reporting, we will look at it.

Best Regards,

Jon

@alex-cooke
Copy link
Author

Hi @JonathanMagnan,

Has there been any progress with this issue?

Cheers,

Alex.

@JonathanMagnan
Copy link
Member

JonathanMagnan commented May 9, 2023

Hello @alex-cooke ,

Sorry for the late reply.

Currently, there is no solution for TPT and TPC for the BulkSynchronize methods. We are currently in discussion to make it works correctly with TPH, but I doubt that any solution for the two other inheritances will come soon.

We are currently re-writing some key code of our library that will eventually be possible to make it happens but that will not be completed before the end of the summer.

So in short, there is currently no solution for TPC + BulkSynchronize.

(I asked my developer to improve the error message to make it more obvious as the current message is missleading)

@alex-cooke
Copy link
Author

Thanks for the update @JonathanMagnan. I'll keep an eye out for updates.

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

No branches or pull requests

2 participants