@swell When I tested this with the code below it worked fine for me. Can you have a look and see what I might be missing from the repro?
Thanks,
Arthur
Thanks,
Arthur
public class Blog
{
public int Id { get; set; }
public string Title { get; set; }
public virtual ICollection<Post> Posts { get; set; }
}
public class Post
{
public int Id { get; set; }
public string Title { get; set; }
public int BlogId { get; set; }
public virtual Blog Blog { get; set; }
}
public class BlogContext : DbContext
{
public const string TestDb =
@"Data Source=.\SQLEXPRESS;Initial Catalog=InvestigateCompatDiscussion.BlogContext;Integrated Security=True;MultipleActiveResultSets=True";
public BlogContext()
: base(TestDb)
{
}
public DbSet<Blog> Blogs { get; set; }
public DbSet<Post> Posts { get; set; }
}
internal class Program
{
private static void Main(string[] args)
{
using (var dbContext = new BlogContext())
{
dbContext.Database.Delete();
}
// Create whole database from migrations
var settings = new DbMigrationsConfiguration<BlogContext>
{
TargetDatabase = new DbConnectionInfo(BlogContext.TestDb, "System.Data.SqlClient"),
AutomaticMigrationsEnabled = true,
AutomaticMigrationDataLossAllowed = true,
MigrationsAssembly = typeof(BlogContext).Assembly,
MigrationsNamespace = "MyContext.Data.Ef.Migrations",
ContextKey = typeof(BlogContext).ToString()
};
var migrator = new DbMigrator(settings);
migrator.Update();
using (var dbContext = new BlogContext())
{
Debug.Assert(dbContext.Database.CompatibleWithModel(true));
}
}
}