EntityFramework-Extensions icon indicating copy to clipboard operation
EntityFramework-Extensions copied to clipboard

"Oops!" Problem with TPC, TPT and BulkSynchronize

Open alex-cooke opened this issue 2 years ago • 4 comments

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!

alex-cooke avatar Apr 25 '23 14:04 alex-cooke

Hello @alex-cooke ,

Thank you for reporting, we will look at it.

Best Regards,

Jon

JonathanMagnan avatar Apr 25 '23 23:04 JonathanMagnan

Hi @JonathanMagnan,

Has there been any progress with this issue?

Cheers,

Alex.

alex-cooke avatar May 08 '23 04:05 alex-cooke

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)

JonathanMagnan avatar May 09 '23 00:05 JonathanMagnan

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

alex-cooke avatar May 30 '23 02:05 alex-cooke