title: In EF Core, how to check whether a migration is needed or not?
body: <p>I am using Entity Framework Core in an Xamarin.iOS application. </p>
  
  <p>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.</p>
  
  <p>Here is the context:</p>
  
  <pre><code>public void Initialize()
  {
     using (var dbContext = new MyDbContext(m_dbContextOptions))
     {
         --&gt; bool isNeeded = demoTapeDbContext.Database.IsMigrationNeeded()
  
         demoTapeDbContext.Database.Migrate();
     }
  }
  </code></pre>
  
  <p>The closest I have found is calling the method <code>GetPendingMigrationsAsync()</code> and check the amount of pending migrations but I am unsure whether it is the safest way to do such check in Entity Framework:</p>
  
  <pre><code>public async Task InitializeAsync()
  {
     using (var dbContext = new MyDbContext(m_dbContextOptions))
     {
         bool isMigrationNeeded = (await demoTapeDbContext.Database.GetPendingMigrationsAsync()).Any();
  
         demoTapeDbContext.Database.Migrate();
     }
  }
  </code></pre>