I am using Entity Framework Core in an Xamarin.iOS application.
In my core project that contains code (.netstandard 2.0) that is shared between the iOS application and other applications, I would like to know if a migration is needed so that I can perform some other operations as well.
Here is the context:
public void Initialize()
{
using (var dbContext = new MyDbContext(m_dbContextOptions))
{
--> bool isNeeded = demoTapeDbContext.Database.IsMigrationNeeded()
demoTapeDbContext.Database.Migrate();
}
}
The closest I have found is calling the method GetPendingMigrationsAsync()
and check the amount of pending migrations but I am unsure whether it is the safest way to do such check in Entity Framework:
public async Task InitializeAsync()
{
using (var dbContext = new MyDbContext(m_dbContextOptions))
{
bool isMigrationNeeded = (await demoTapeDbContext.Database.GetPendingMigrationsAsync()).Any();
demoTapeDbContext.Database.Migrate();
}
}
context.Database.Migrate();
which was working fine with 1 instance of our application, but now we need have 2 instances and we are facing the error where application can not insert duplicate migration. Probably we are facing this error because both instances after deployment are trying to execute the same migration. Would this checkcontext.Database.GetPendingMigrations().Any())
be a fix for that error as well? Would this be a fix for the issue I'm facing, the thing is we horizontally scaled our application – Papillary