Dotnet Core 3.1 Entity Framework - Issues with entity.SetTableName not currently available

c# entity-framework-core

Question

Unfortunately I have found myself doing a full ground up rebuild with my code as the solution was taking 5 minutes to build. I decided to take the opportunity to move to dotnet core 3.1.

However, I have found that the option .SetTableName is not available as part of "entity".

I am using it as part of setting shadow properties in the DbContext. Here is my code.

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        foreach (var entity in modelBuilder.Model.GetEntityTypes())
        {
            //entity.Relational().TableName = entity.DisplayName(); // Dotnet Core 2...
            entity.SetTableName(entity.DisplayName());  //HERE
        }

        modelBuilder.ShadowProperties(); // Adding in the shadow properties here..
        ...

Is there another way to set the table name in this scenario and if not are there other options?

1
0
12/8/2019 9:28:50 AM

Popular Answer

I think the following code will help you, You can use Data Annotations or Fluent API

Data Annotations:

[Table("blogs")]
public class Blog
{
  public int BlogId { get; set; }
  public string Url { get; set; }
}

Or:

[Table("blogs", Schema = "blogging")]
public class Blog
{
   public int BlogId { get; set; }
   public string Url { get; set; }
}

Fluent API:

modelBuilder.Entity<Blog>().ToTable("blogs", schema: "blogging");
0
12/8/2019 9:33:10 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow