Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I played around with the code you provided and in this case (with SQL Server instead of CE) and have arrived at the following. I've removed the Database.Create code and allowed EF's automatic migrations to do it's thing. This runs through and calls the Seed method correctly now.</p> <pre><code>internal class Program { private static void Main() { EntityFrameworkProfiler.Initialize(); Database.DefaultConnectionFactory = new SqlConnectionFactory("System.Data.SqlServer"); Database.SetInitializer(new MigrateDatabaseToLatestVersion&lt;MyContext, MyContextConfiguration&gt;()); using (var context = new MyContext()) { var element = context.Dummies.FirstOrDefault(); } } } internal class Dummy { public String Id { get; set; } } internal sealed class MyContext : DbContext { public MyContext() : base(@"Data Source=localhost;Initial Catalog=Dummies;User Id=&lt;USER_ID&gt;;Password=&lt;PASSWORD&gt;;MultipleActiveResultSets=False;") { } public DbSet&lt;Dummy&gt; Dummies { get; set; } } internal sealed class MyContextConfiguration : DbMigrationsConfiguration&lt;MyContext&gt; { public MyContextConfiguration() { AutomaticMigrationsEnabled = true; AutomaticMigrationDataLossAllowed = true; } protected override void Seed(MyContext context) { context.Dummies.AddOrUpdate(new Dummy() { Id = "First" }); } } </code></pre> <p>If you look in EF profiler, you'll see there are more queries run against the DB now (and even a check for the old EdmMetaData table... which is very odd, as it should drop that table if it's encountered now in favour of the __MigrationHistory table). I don't know why this is happening, I guess it's either a configuration issue our side (of which I don't yet know how to fix) or it's a bug in the migrations code.</p> <p>So, I think with EF migrations we're either left to code based migrations (<a href="http://www.terric.co.uk/code-first-entity-framework-and-sql-migrations/" rel="nofollow">see my blog post here</a>) or automatic migrations (as this code snippet demonstrates). I guess as time goes on I'll get a better understanding of why EF (or the way I migrate) has this strange behaviour - or EF itself will get better as it evolves.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload