EntityTypeBuilder does not contain a definition for ToTable in EF Core

前端 未结 12 1465
南笙
南笙 2021-02-06 20:22

I have this sample code:

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Models;

namespace MySampleNamespace
{         


        
12条回答
  •  天涯浪人
    2021-02-06 20:46

    For EFCore 3.1 I needed to use this in my DB context:

    protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
    
            foreach (IMutableEntityType entity in modelBuilder.Model.GetEntityTypes())
            {
                entity.SetTableName("WS_" + entity.GetTableName());
            }
        }
    

    No additional Nuget package was required.

提交回复
热议问题