I am trying to create a Microservices architecture. I have a stateless service in conjunction with the Entity Framework deployed to the Labur Service Cluster Fabric. However, my problem is that when I have an initializer with DropCreateDatabase, the database is deleted but not recreated.
I have the following initializer:
class CompanyInitializer : DropCreateDatabaseAlways<CompanyContext>
{
protected override void Seed(CompanyContext context)
{
var companies = new List<Company>
{
new Company { Name = "AAA", City = "Eindhoven", Streetname="Street 12" },
new Company { Name = "BBB", City = "Rotterdam", Streetname = "Street 12" },
new Company { Name = "CCC", City = "Eindhoven", Streetname = "Street 12" }
};
companies.ForEach(s => context.Companies.Add(s));
context.SaveChanges();
base.Seed(context);
}
}
In the following context:
public class CompanyContext : DbContext
{
public CompanyContext(string connectionString) : base(connectionString)
{
this.Database.Connection.ConnectionString = connectionString;
Database.SetInitializer<CompanyContext>(new CompanyInitializer());
}
public DbSet<Company> Companies { get; set; }
}
And I connect them through the stateless service constructor:
public StatelessServiceCompany(StatelessServiceContext context)
: base(context)
{
_databaseConnectionstring = WebConfigurationManager.AppSettings["Entity.Framework.ConnectionString"];
_context = new CompanyContext(_databaseConnectionstring);
new CompanyInitializer().InitializeDatabase(_context);
}
And the connection string is as follows:
Data Source=*****.*****.****.***;Initial Catalog=******;Integrated Security=False;User ID=********;Password=********;Connect Timeout=30;Encrypt=True;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False
The problem is that the database is deleted, but never recreated. I believe that there are no rights to create a database using code on the Azure platform.
-, . :
"System.BadImageFormatException: " StatelessServiceCompany " . ."
. Entity Framework Ado.net.
Edit
, . "" > "". x64 x86, , . seed .