PawelGerr/Thinktecture.EntityFrameworkCore

"TempTable<DateTime>' is sealed." Is it possible to use TempTables with Lazy Loading enabled?

karoletrych opened this issue · 2 comments

I have LazyLoading enabled:

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        base.OnConfiguring(optionsBuilder);

        optionsBuilder.UseLazyLoadingProxies();

I've added

                               .UseSqlServer("conn-string", sqlOptions =>
                                                            {
                                                                 sqlOptions.AddBulkOperationSupport();
                                                            })

and I'm getting the following error:

Entity type 'Thinktecture:TempTable:Thinktecture.EntityFrameworkCore.TempTables.TempTable<DateTime> (TempTable<DateTime>)' is sealed. 'UseChangeTrackingProxies' requires all entity types to be public, unsealed, have virtual properties, and have a public or protected constructor. 'UseLazyLoadingProxies' requires only the navigation properties be virtual."

Yes, you have to disable the registrations of TempTable<T> the library does for you automatically.
Set configureTempTablesForPrimitiveTypes to false and use custom types for temp tables.

services.AddDbContext<DemoDbContext>(builder => builder
       .UseSqlServer("conn-string", sqlOptions =>
         {
            sqlOptions.AddBulkOperationSupport(configureTempTablesForPrimitiveTypes: false);
         })

Example of registration of custom type as a temp table

modelBuilder.ConfigureTempTableEntity<MyTempTable>();

// or

modelBuilder.ConfigureTempTableEntity<MyTempTable>(builder =>
                       {
                          builder.Property(e => e.MyDecimalProperty).HasPrecision(10, 5);
                          builder.Property(e => e.MyStringProperty).HasMaxLength(200);
                       });

It worked! Thank you very much!