Entity Framework builder try to generate the table twice

0

The following code always tries to generate the server database table twice.

User

public class User : IdentityUser {
  public ICollection<IdentityRole> UserRoles { get; set; }

  public virtual ICollection<UserServer> Servers { get; set; }
}

TestServer

public class TestServer {
  public string TestServerId { get; set; }

  // This throw the error
  [InverseProperty("User")]
  public string UserId { get; set; }
  public virtual User.User User { get; set; }
}

Program

// Entity Framework startup for generating the database tables.
....
// User
var userContext = services.GetRequiredService<UserContext>();
userContext.Database.EnsureCreated();
UserContextInitializer.Initialize(userContext);

// Server
var serverContext = services.GetRequiredService<ServerContext>();
serverContext.Database.EnsureCreated();
ServerContextInitializer.Initialize(serverContext);

// TestServer
// Error throw here: Table 'Server' already exists ---> MySql.Data.MySqlClient.MySqlException (0x80004005): Table 'Server' already exists

var testServerContxt = services.GetRequiredService<TestServerContext>();
var creator2 = (RelationalDatabaseCreator) testServerContxt.Database.GetService<IRelationalDatabaseCreator>();
creator2.CreateTables();
testServerContxt.Database.EnsureCreated();

Why is Entity Framework attempting to generate the Server table and not TestServer table?

Thanks in advance.

Regards Timo

asp.net
database
.net-core
entity-framework-core
asked on Stack Overflow May 29, 2019 by Timo Falter • edited May 29, 2019 by marc_s

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0