// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Collections.Generic; using System.Data.Common; using System.Data.Jet; using System.Threading.Tasks; using EntityFrameworkCore.Jet.FunctionalTests.TestUtilities; using EntityFrameworkCore.Jet.Metadata; using Identity30.Data; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; using EntityFrameworkCore.Jet.Storage.Internal; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.TestModels.AspNetIdentity; using Microsoft.EntityFrameworkCore.TestUtilities; using Xunit; using JetDatabaseCreator = EntityFrameworkCore.Jet.Storage.Internal.JetDatabaseCreator; // ReSharper disable InconsistentNaming namespace EntityFrameworkCore.Jet.FunctionalTests { [JetCondition(JetCondition.IsNotCI)] public class MigrationsJetTest : MigrationsTestBase { public MigrationsJetTest(MigrationsJetFixture fixture) : base(fixture) { } public override void Can_generate_migration_from_initial_database_to_initial() { base.Can_generate_migration_from_initial_database_to_initial(); Assert.Equal( @"IF OBJECT_ID('`__EFMigrationsHistory`') IS NULL BEGIN CREATE TABLE `__EFMigrationsHistory` ( `MigrationId` nvarchar(150) NOT NULL, `ProductVersion` nvarchar(32) NOT NULL, CONSTRAINT `PK___EFMigrationsHistory` PRIMARY KEY (`MigrationId`) ); END; GO ", Sql, ignoreLineEndingDifferences: true); } public override void Can_generate_no_migration_script() { base.Can_generate_no_migration_script(); Assert.Equal( @"IF OBJECT_ID('`__EFMigrationsHistory`') IS NULL BEGIN CREATE TABLE `__EFMigrationsHistory` ( `MigrationId` nvarchar(150) NOT NULL, `ProductVersion` nvarchar(32) NOT NULL, CONSTRAINT `PK___EFMigrationsHistory` PRIMARY KEY (`MigrationId`) ); END; GO ", Sql, ignoreLineEndingDifferences: true); } public override void Can_generate_up_scripts() { base.Can_generate_up_scripts(); Assert.Equal( @"IF OBJECT_ID('`__EFMigrationsHistory`') IS NULL BEGIN CREATE TABLE `__EFMigrationsHistory` ( `MigrationId` nvarchar(150) NOT NULL, `ProductVersion` nvarchar(32) NOT NULL, CONSTRAINT `PK___EFMigrationsHistory` PRIMARY KEY (`MigrationId`) ); END; GO CREATE TABLE `Table1` ( `Id` int NOT NULL, `Foo` int NOT NULL, CONSTRAINT `PK_Table1` PRIMARY KEY (`Id`) ); GO INSERT INTO `__EFMigrationsHistory` (`MigrationId`, `ProductVersion`) VALUES ('00000000000001_Migration1', '7.0.0-test'); GO EXEC sp_rename '`Table1`.`Foo`', 'Bar', 'COLUMN'; GO INSERT INTO `__EFMigrationsHistory` (`MigrationId`, `ProductVersion`) VALUES ('00000000000002_Migration2', '7.0.0-test'); GO CREATE DATABASE TransactionSuppressed; GO DROP DATABASE TransactionSuppressed; GO INSERT INTO `__EFMigrationsHistory` (`MigrationId`, `ProductVersion`) VALUES ('00000000000003_Migration3', '7.0.0-test'); GO ", Sql, ignoreLineEndingDifferences: true); } public override void Can_generate_one_up_script() { base.Can_generate_one_up_script(); Assert.Equal( @"EXEC sp_rename '`Table1`.`Foo`', 'Bar', 'COLUMN'; GO INSERT INTO `__EFMigrationsHistory` (`MigrationId`, `ProductVersion`) VALUES ('00000000000002_Migration2', '7.0.0-test'); GO ", Sql, ignoreLineEndingDifferences: true); } public override void Can_generate_up_script_using_names() { base.Can_generate_up_script_using_names(); Assert.Equal( @"EXEC sp_rename '`Table1`.`Foo`', 'Bar', 'COLUMN'; GO INSERT INTO `__EFMigrationsHistory` (`MigrationId`, `ProductVersion`) VALUES ('00000000000002_Migration2', '7.0.0-test'); GO ", Sql, ignoreLineEndingDifferences: true); } public override void Can_generate_idempotent_up_scripts() { base.Can_generate_idempotent_up_scripts(); Assert.Equal( @"IF OBJECT_ID('`__EFMigrationsHistory`') IS NULL BEGIN CREATE TABLE `__EFMigrationsHistory` ( `MigrationId` nvarchar(150) NOT NULL, `ProductVersion` nvarchar(32) NOT NULL, CONSTRAINT `PK___EFMigrationsHistory` PRIMARY KEY (`MigrationId`) ); END; GO IF NOT EXISTS(SELECT * FROM `__EFMigrationsHistory` WHERE `MigrationId` = '00000000000001_Migration1') BEGIN CREATE TABLE `Table1` ( `Id` int NOT NULL, `Foo` int NOT NULL, CONSTRAINT `PK_Table1` PRIMARY KEY (`Id`) ); END; GO IF NOT EXISTS(SELECT * FROM `__EFMigrationsHistory` WHERE `MigrationId` = '00000000000001_Migration1') BEGIN INSERT INTO `__EFMigrationsHistory` (`MigrationId`, `ProductVersion`) VALUES ('00000000000001_Migration1', '7.0.0-test'); END; GO IF NOT EXISTS(SELECT * FROM `__EFMigrationsHistory` WHERE `MigrationId` = '00000000000002_Migration2') BEGIN EXEC sp_rename '`Table1`.`Foo`', 'Bar', 'COLUMN'; END; GO IF NOT EXISTS(SELECT * FROM `__EFMigrationsHistory` WHERE `MigrationId` = '00000000000002_Migration2') BEGIN INSERT INTO `__EFMigrationsHistory` (`MigrationId`, `ProductVersion`) VALUES ('00000000000002_Migration2', '7.0.0-test'); END; GO IF NOT EXISTS(SELECT * FROM `__EFMigrationsHistory` WHERE `MigrationId` = '00000000000003_Migration3') BEGIN CREATE DATABASE TransactionSuppressed; END; GO IF NOT EXISTS(SELECT * FROM `__EFMigrationsHistory` WHERE `MigrationId` = '00000000000003_Migration3') BEGIN DROP DATABASE TransactionSuppressed; END; GO IF NOT EXISTS(SELECT * FROM `__EFMigrationsHistory` WHERE `MigrationId` = '00000000000003_Migration3') BEGIN INSERT INTO `__EFMigrationsHistory` (`MigrationId`, `ProductVersion`) VALUES ('00000000000003_Migration3', '7.0.0-test'); END; GO ", Sql, ignoreLineEndingDifferences: true); } public override void Can_generate_down_scripts() { base.Can_generate_down_scripts(); Assert.Equal( @"EXEC sp_rename '`Table1`.`Bar`', 'Foo', 'COLUMN'; GO DELETE FROM `__EFMigrationsHistory` WHERE `MigrationId` = '00000000000002_Migration2'; GO DROP TABLE `Table1`; GO DELETE FROM `__EFMigrationsHistory` WHERE `MigrationId` = '00000000000001_Migration1'; GO ", Sql, ignoreLineEndingDifferences: true); } public override void Can_generate_idempotent_down_scripts() { base.Can_generate_idempotent_down_scripts(); Assert.Equal( @"IF EXISTS(SELECT * FROM `__EFMigrationsHistory` WHERE `MigrationId` = '00000000000002_Migration2') BEGIN EXEC sp_rename '`Table1`.`Bar`', 'Foo', 'COLUMN'; END; GO IF EXISTS(SELECT * FROM `__EFMigrationsHistory` WHERE `MigrationId` = '00000000000002_Migration2') BEGIN DELETE FROM `__EFMigrationsHistory` WHERE `MigrationId` = '00000000000002_Migration2'; END; GO IF EXISTS(SELECT * FROM `__EFMigrationsHistory` WHERE `MigrationId` = '00000000000001_Migration1') BEGIN DROP TABLE `Table1`; END; GO IF EXISTS(SELECT * FROM `__EFMigrationsHistory` WHERE `MigrationId` = '00000000000001_Migration1') BEGIN DELETE FROM `__EFMigrationsHistory` WHERE `MigrationId` = '00000000000001_Migration1'; END; GO ", Sql, ignoreLineEndingDifferences: true); } public override void Can_generate_one_down_script() { base.Can_generate_one_down_script(); Assert.Equal( @"EXEC sp_rename '`Table1`.`Bar`', 'Foo', 'COLUMN'; GO DELETE FROM `__EFMigrationsHistory` WHERE `MigrationId` = '00000000000002_Migration2'; GO ", Sql, ignoreLineEndingDifferences: true); } public override void Can_generate_down_script_using_names() { base.Can_generate_down_script_using_names(); Assert.Equal( @"EXEC sp_rename '`Table1`.`Bar`', 'Foo', 'COLUMN'; GO DELETE FROM `__EFMigrationsHistory` WHERE `MigrationId` = '00000000000002_Migration2'; GO ", Sql, ignoreLineEndingDifferences: true); } public override void Can_get_active_provider() { base.Can_get_active_provider(); Assert.Equal("EntityFrameworkCore.Jet", ActiveProvider); } protected override async Task AssertFirstMigrationAsync(DbConnection connection) { var sql = await GetDatabaseSchemaAsync(connection); Assert.Equal( @" CreatedTable Id int NOT NULL ColumnWithDefaultToDrop int NULL DEFAULT ((0)) ColumnWithDefaultToAlter int NULL DEFAULT ((1)) Foos Id int NOT NULL ", sql, ignoreLineEndingDifferences: true); } protected override async Task AssertSecondMigrationAsync(DbConnection connection) { var sql = await GetDatabaseSchemaAsync(connection); Assert.Equal( @" CreatedTable Id int NOT NULL ColumnWithDefaultToAlter int NULL Foos Id int NOT NULL ", sql, ignoreLineEndingDifferences: true); } private async Task GetDatabaseSchemaAsync(DbConnection connection) { var builder = new IndentedStringBuilder(); var command = connection.CreateCommand(); command.CommandText = @" SELECT t.name, c.Name, TYPE_NAME(c.user_type_id), c.is_nullable, d.Definition FROM sys.objects t LEFT JOIN sys.columns c ON c.object_id = t.object_id LEFT JOIN sys.default_constraints d ON d.parent_column_id = c.column_id AND d.parent_object_id = t.object_id WHERE t.type = 'U' ORDER BY t.name, c.column_id;"; using (var reader = await command.ExecuteReaderAsync()) { var first = true; string lastTable = null; while (await reader.ReadAsync()) { var currentTable = reader.GetString(0); if (currentTable != lastTable) { if (first) { first = false; } else { builder.DecrementIndent(); } builder .AppendLine() .AppendLine(currentTable) .IncrementIndent(); lastTable = currentTable; } builder .Append(reader[1]) // Name .Append(" ") .Append(reader[2]) // Type .Append(" ") .Append(reader.GetBoolean(3) ? "NULL" : "NOT NULL"); if (!await reader.IsDBNullAsync(4)) { builder .Append(" DEFAULT ") .Append(reader[4]); } builder.AppendLine(); } } return builder.ToString(); } [ConditionalFact] public async Task Empty_Migration_Creates_Database() { using (var context = new BloggingContext( Fixture.TestStore.AddProviderOptions( new DbContextOptionsBuilder().EnableServiceProviderCaching(false)).Options)) { var creator = (JetDatabaseCreator)context.GetService(); // creator.RetryTimeout = TimeSpan.FromMinutes(10); await context.Database.MigrateAsync(); Assert.True(creator.Exists()); } } private class BloggingContext : DbContext { public BloggingContext(DbContextOptions options) : base(options) { } // ReSharper disable once UnusedMember.Local public DbSet Blogs { get; set; } // ReSharper disable once ClassNeverInstantiated.Local public class Blog { // ReSharper disable UnusedMember.Local public int Id { get; set; } public string Name { get; set; } // ReSharper restore UnusedMember.Local } } [DbContext(typeof(BloggingContext))] [Migration("00000000000000_Empty")] public class EmptyMigration : Migration { protected override void Up(MigrationBuilder migrationBuilder) { } } public override void Can_diff_against_2_2_model() { using (var context = new ModelSnapshot22.BloggingContext()) { DiffSnapshot(new BloggingContextModelSnapshot22(), context); } } public class BloggingContextModelSnapshot22 : ModelSnapshot { protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder .HasAnnotation("ProductVersion", "2.2.4-servicing-10062") .HasAnnotation("Relational:MaxIdentifierLength", 128) .HasAnnotation("Jet:ValueGenerationStrategy", JetValueGenerationStrategy.IdentityColumn); modelBuilder.Entity( "ModelSnapshot22.Blog", b => { b.Property("Id") .ValueGeneratedOnAdd() .HasAnnotation("Jet:ValueGenerationStrategy", JetValueGenerationStrategy.IdentityColumn); b.Property("Name"); b.HasKey("Id"); b.ToTable("Blogs"); b.HasData( new { Id = 1, Name = "HalfADonkey" }); }); modelBuilder.Entity( "ModelSnapshot22.Post", b => { b.Property("Id") .ValueGeneratedOnAdd() .HasAnnotation("Jet:ValueGenerationStrategy", JetValueGenerationStrategy.IdentityColumn); b.Property("BlogId"); b.Property("Content"); b.Property("EditDate"); b.Property("Title"); b.HasKey("Id"); b.HasIndex("BlogId"); b.ToTable("Post"); }); modelBuilder.Entity( "ModelSnapshot22.Post", b => { b.HasOne("ModelSnapshot22.Blog", "Blog") .WithMany("Posts") .HasForeignKey("BlogId"); }); #pragma warning restore 612, 618 } } public override void Can_diff_against_2_1_ASP_NET_Identity_model() { using (var context = new ApplicationDbContext()) { DiffSnapshot(new AspNetIdentity21ModelSnapshot(), context); } } public class AspNetIdentity21ModelSnapshot : ModelSnapshot { protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder .HasAnnotation("ProductVersion", "2.1.0") .HasAnnotation("Relational:MaxIdentifierLength", 128) .HasAnnotation("Jet:ValueGenerationStrategy", JetValueGenerationStrategy.IdentityColumn); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityRole", b => { b.Property("Id") .ValueGeneratedOnAdd(); b.Property("ConcurrencyStamp") .IsConcurrencyToken(); b.Property("Name") .HasMaxLength(256); b.Property("NormalizedName") .HasMaxLength(256); b.HasKey("Id"); b.HasIndex("NormalizedName") .IsUnique() .HasName("RoleNameIndex") .HasFilter("`NormalizedName` IS NOT NULL"); b.ToTable("AspNetRoles"); }); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => { b.Property("Id") .ValueGeneratedOnAdd() .HasAnnotation("Jet:ValueGenerationStrategy", JetValueGenerationStrategy.IdentityColumn); b.Property("ClaimType"); b.Property("ClaimValue"); b.Property("RoleId") .IsRequired(); b.HasKey("Id"); b.HasIndex("RoleId"); b.ToTable("AspNetRoleClaims"); }); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityUser", b => { b.Property("Id") .ValueGeneratedOnAdd(); b.Property("AccessFailedCount"); b.Property("ConcurrencyStamp") .IsConcurrencyToken(); b.Property("Email") .HasMaxLength(256); b.Property("EmailConfirmed"); b.Property("LockoutEnabled"); b.Property("LockoutEnd"); b.Property("NormalizedEmail") .HasMaxLength(256); b.Property("NormalizedUserName") .HasMaxLength(256); b.Property("PasswordHash"); b.Property("PhoneNumber"); b.Property("PhoneNumberConfirmed"); b.Property("SecurityStamp"); b.Property("TwoFactorEnabled"); b.Property("UserName") .HasMaxLength(256); b.HasKey("Id"); b.HasIndex("NormalizedEmail") .HasName("EmailIndex"); b.HasIndex("NormalizedUserName") .IsUnique() .HasName("UserNameIndex") .HasFilter("`NormalizedUserName` IS NOT NULL"); b.ToTable("AspNetUsers"); }); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityUserClaim", b => { b.Property("Id") .ValueGeneratedOnAdd() .HasAnnotation("Jet:ValueGenerationStrategy", JetValueGenerationStrategy.IdentityColumn); b.Property("ClaimType"); b.Property("ClaimValue"); b.Property("UserId") .IsRequired(); b.HasKey("Id"); b.HasIndex("UserId"); b.ToTable("AspNetUserClaims"); }); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityUserLogin", b => { b.Property("LoginProvider") .HasMaxLength(128); b.Property("ProviderKey") .HasMaxLength(128); b.Property("ProviderDisplayName"); b.Property("UserId") .IsRequired(); b.HasKey("LoginProvider", "ProviderKey"); b.HasIndex("UserId"); b.ToTable("AspNetUserLogins"); }); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityUserRole", b => { b.Property("UserId"); b.Property("RoleId"); b.HasKey("UserId", "RoleId"); b.HasIndex("RoleId"); b.ToTable("AspNetUserRoles"); }); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityUserToken", b => { b.Property("UserId"); b.Property("LoginProvider") .HasMaxLength(128); b.Property("Name") .HasMaxLength(128); b.Property("Value"); b.HasKey("UserId", "LoginProvider", "Name"); b.ToTable("AspNetUserTokens"); }); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => { b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole") .WithMany() .HasForeignKey("RoleId") .OnDelete(DeleteBehavior.Cascade); }); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityUserClaim", b => { b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") .WithMany() .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade); }); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityUserLogin", b => { b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") .WithMany() .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade); }); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityUserRole", b => { b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole") .WithMany() .HasForeignKey("RoleId") .OnDelete(DeleteBehavior.Cascade); b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") .WithMany() .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade); }); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityUserToken", b => { b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") .WithMany() .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade); }); #pragma warning restore 612, 618 } } public override void Can_diff_against_2_2_ASP_NET_Identity_model() { using (var context = new ApplicationDbContext()) { DiffSnapshot(new AspNetIdentity22ModelSnapshot(), context); } } public class AspNetIdentity22ModelSnapshot : ModelSnapshot { protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder .HasAnnotation("ProductVersion", "2.2.0-preview1") .HasAnnotation("Relational:MaxIdentifierLength", 128) .HasAnnotation("Jet:ValueGenerationStrategy", JetValueGenerationStrategy.IdentityColumn); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityRole", b => { b.Property("Id") .ValueGeneratedOnAdd(); b.Property("ConcurrencyStamp") .IsConcurrencyToken(); b.Property("Name") .HasMaxLength(256); b.Property("NormalizedName") .HasMaxLength(256); b.HasKey("Id"); b.HasIndex("NormalizedName") .IsUnique() .HasName("RoleNameIndex") .HasFilter("`NormalizedName` IS NOT NULL"); b.ToTable("AspNetRoles"); }); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => { b.Property("Id") .ValueGeneratedOnAdd() .HasAnnotation("Jet:ValueGenerationStrategy", JetValueGenerationStrategy.IdentityColumn); b.Property("ClaimType"); b.Property("ClaimValue"); b.Property("RoleId") .IsRequired(); b.HasKey("Id"); b.HasIndex("RoleId"); b.ToTable("AspNetRoleClaims"); }); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityUser", b => { b.Property("Id") .ValueGeneratedOnAdd(); b.Property("AccessFailedCount"); b.Property("ConcurrencyStamp") .IsConcurrencyToken(); b.Property("Email") .HasMaxLength(256); b.Property("EmailConfirmed"); b.Property("LockoutEnabled"); b.Property("LockoutEnd"); b.Property("NormalizedEmail") .HasMaxLength(256); b.Property("NormalizedUserName") .HasMaxLength(256); b.Property("PasswordHash"); b.Property("PhoneNumber"); b.Property("PhoneNumberConfirmed"); b.Property("SecurityStamp"); b.Property("TwoFactorEnabled"); b.Property("UserName") .HasMaxLength(256); b.HasKey("Id"); b.HasIndex("NormalizedEmail") .HasName("EmailIndex"); b.HasIndex("NormalizedUserName") .IsUnique() .HasName("UserNameIndex") .HasFilter("`NormalizedUserName` IS NOT NULL"); b.ToTable("AspNetUsers"); }); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityUserClaim", b => { b.Property("Id") .ValueGeneratedOnAdd() .HasAnnotation("Jet:ValueGenerationStrategy", JetValueGenerationStrategy.IdentityColumn); b.Property("ClaimType"); b.Property("ClaimValue"); b.Property("UserId") .IsRequired(); b.HasKey("Id"); b.HasIndex("UserId"); b.ToTable("AspNetUserClaims"); }); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityUserLogin", b => { b.Property("LoginProvider") .HasMaxLength(128); b.Property("ProviderKey") .HasMaxLength(128); b.Property("ProviderDisplayName"); b.Property("UserId") .IsRequired(); b.HasKey("LoginProvider", "ProviderKey"); b.HasIndex("UserId"); b.ToTable("AspNetUserLogins"); }); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityUserRole", b => { b.Property("UserId"); b.Property("RoleId"); b.HasKey("UserId", "RoleId"); b.HasIndex("RoleId"); b.ToTable("AspNetUserRoles"); }); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityUserToken", b => { b.Property("UserId"); b.Property("LoginProvider") .HasMaxLength(128); b.Property("Name") .HasMaxLength(128); b.Property("Value"); b.HasKey("UserId", "LoginProvider", "Name"); b.ToTable("AspNetUserTokens"); }); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => { b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole") .WithMany() .HasForeignKey("RoleId") .OnDelete(DeleteBehavior.Cascade); }); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityUserClaim", b => { b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") .WithMany() .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade); }); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityUserLogin", b => { b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") .WithMany() .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade); }); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityUserRole", b => { b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole") .WithMany() .HasForeignKey("RoleId") .OnDelete(DeleteBehavior.Cascade); b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") .WithMany() .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade); }); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityUserToken", b => { b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser") .WithMany() .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade); }); #pragma warning restore 612, 618 } } public override void Can_diff_against_3_0_ASP_NET_Identity_model() { using (var context = new ApplicationDbContext()) { DiffSnapshot(new AspNetIdentity30ModelSnapshot(), context); } } public class AspNetIdentity30ModelSnapshot : ModelSnapshot { protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder .HasAnnotation("ProductVersion", "3.0.0") .HasAnnotation("Relational:MaxIdentifierLength", 128) .HasAnnotation("Jet:ValueGenerationStrategy", JetValueGenerationStrategy.IdentityColumn); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityRole", b => { b.Property("Id") .HasColumnType("nvarchar(450)"); b.Property("ConcurrencyStamp") .IsConcurrencyToken() .HasColumnType("nvarchar(max)"); b.Property("Name") .HasColumnType("nvarchar(256)") .HasMaxLength(256); b.Property("NormalizedName") .HasColumnType("nvarchar(256)") .HasMaxLength(256); b.HasKey("Id"); b.HasIndex("NormalizedName") .IsUnique() .HasName("RoleNameIndex") .HasFilter("`NormalizedName` IS NOT NULL"); b.ToTable("AspNetRoles"); }); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => { b.Property("Id") .ValueGeneratedOnAdd() .HasColumnType("int") .HasAnnotation("Jet:ValueGenerationStrategy", JetValueGenerationStrategy.IdentityColumn); b.Property("ClaimType") .HasColumnType("nvarchar(max)"); b.Property("ClaimValue") .HasColumnType("nvarchar(max)"); b.Property("RoleId") .IsRequired() .HasColumnType("nvarchar(450)"); b.HasKey("Id"); b.HasIndex("RoleId"); b.ToTable("AspNetRoleClaims"); }); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityUser", b => { b.Property("Id") .HasColumnType("nvarchar(450)"); b.Property("AccessFailedCount") .HasColumnType("int"); b.Property("ConcurrencyStamp") .IsConcurrencyToken() .HasColumnType("nvarchar(max)"); b.Property("Email") .HasColumnType("nvarchar(256)") .HasMaxLength(256); b.Property("EmailConfirmed") .HasColumnType("bit"); b.Property("LockoutEnabled") .HasColumnType("bit"); b.Property("LockoutEnd") .HasColumnType("datetimeoffset"); b.Property("NormalizedEmail") .HasColumnType("nvarchar(256)") .HasMaxLength(256); b.Property("NormalizedUserName") .HasColumnType("nvarchar(256)") .HasMaxLength(256); b.Property("PasswordHash") .HasColumnType("nvarchar(max)"); b.Property("PhoneNumber") .HasColumnType("nvarchar(max)"); b.Property("PhoneNumberConfirmed") .HasColumnType("bit"); b.Property("SecurityStamp") .HasColumnType("nvarchar(max)"); b.Property("TwoFactorEnabled") .HasColumnType("bit"); b.Property("UserName") .HasColumnType("nvarchar(256)") .HasMaxLength(256); b.HasKey("Id"); b.HasIndex("NormalizedEmail") .HasName("EmailIndex"); b.HasIndex("NormalizedUserName") .IsUnique() .HasName("UserNameIndex") .HasFilter("`NormalizedUserName` IS NOT NULL"); b.ToTable("AspNetUsers"); }); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityUserClaim", b => { b.Property("Id") .ValueGeneratedOnAdd() .HasColumnType("int") .HasAnnotation("Jet:ValueGenerationStrategy", JetValueGenerationStrategy.IdentityColumn); b.Property("ClaimType") .HasColumnType("nvarchar(max)"); b.Property("ClaimValue") .HasColumnType("nvarchar(max)"); b.Property("UserId") .IsRequired() .HasColumnType("nvarchar(450)"); b.HasKey("Id"); b.HasIndex("UserId"); b.ToTable("AspNetUserClaims"); }); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityUserLogin", b => { b.Property("LoginProvider") .HasColumnType("nvarchar(128)") .HasMaxLength(128); b.Property("ProviderKey") .HasColumnType("nvarchar(128)") .HasMaxLength(128); b.Property("ProviderDisplayName") .HasColumnType("nvarchar(max)"); b.Property("UserId") .IsRequired() .HasColumnType("nvarchar(450)"); b.HasKey("LoginProvider", "ProviderKey"); b.HasIndex("UserId"); b.ToTable("AspNetUserLogins"); }); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityUserRole", b => { b.Property("UserId") .HasColumnType("nvarchar(450)"); b.Property("RoleId") .HasColumnType("nvarchar(450)"); b.HasKey("UserId", "RoleId"); b.HasIndex("RoleId"); b.ToTable("AspNetUserRoles"); }); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityUserToken", b => { b.Property("UserId") .HasColumnType("nvarchar(450)"); b.Property("LoginProvider") .HasColumnType("nvarchar(128)") .HasMaxLength(128); b.Property("Name") .HasColumnType("nvarchar(128)") .HasMaxLength(128); b.Property("Value") .HasColumnType("nvarchar(max)"); b.HasKey("UserId", "LoginProvider", "Name"); b.ToTable("AspNetUserTokens"); }); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => { b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) .WithMany() .HasForeignKey("RoleId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); }); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityUserClaim", b => { b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) .WithMany() .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); }); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityUserLogin", b => { b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) .WithMany() .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); }); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityUserRole", b => { b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) .WithMany() .HasForeignKey("RoleId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) .WithMany() .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); }); modelBuilder.Entity( "Microsoft.AspNetCore.Identity.IdentityUserToken", b => { b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) .WithMany() .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); }); #pragma warning restore 612, 618 } } } } namespace ModelSnapshot22 { public class Blog { public int Id { get; set; } public string Name { get; set; } public ICollection Posts { get; set; } } public class Post { public int Id { get; set; } public string Title { get; set; } public string Content { get; set; } public DateTime EditDate { get; set; } public Blog Blog { get; set; } } public class BloggingContext : DbContext { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) => optionsBuilder.UseJet(@"Server=(localdb)\mssqllocaldb;Database=Test;ConnectRetryCount=0", TestEnvironment.DataAccessProviderFactory); public DbSet Blogs { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity().HasData( new Blog { Id = 1, Name = "HalfADonkey" }); } } } namespace Identity30.Data { public class ApplicationDbContext : IdentityDbContext { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) => optionsBuilder.UseJet(@"Server=(localdb)\mssqllocaldb;Database=Test;ConnectRetryCount=0", TestEnvironment.DataAccessProviderFactory); protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); builder.Entity( b => { b.HasIndex(u => u.NormalizedUserName).HasName("UserNameIndex").IsUnique(); b.HasIndex(u => u.NormalizedEmail).HasName("EmailIndex"); b.ToTable("AspNetUsers"); }); builder.Entity>( b => { b.ToTable("AspNetUserClaims"); }); builder.Entity>( b => { b.ToTable("AspNetUserLogins"); }); builder.Entity>( b => { b.ToTable("AspNetUserTokens"); }); builder.Entity( b => { b.HasIndex(r => r.NormalizedName).HasName("RoleNameIndex").IsUnique(); b.ToTable("AspNetRoles"); }); builder.Entity>( b => { b.ToTable("AspNetRoleClaims"); }); builder.Entity>( b => { b.ToTable("AspNetUserRoles"); }); } } }