From 95b28641ed62a1cb585e1e07b03aeab4ef19e072 Mon Sep 17 00:00:00 2001 From: Marinko Date: Sun, 12 Jan 2020 09:57:33 +0100 Subject: [PATCH 1/2] Source code for the first part of the series --- .gitignore | 3 + .../IdentityByExamples.csproj | 1 + ...0191202135856_InitialMigration.Designer.cs | 64 ++++ .../20191202135856_InitialMigration.cs | 41 +++ ...2142926_CreatingIdentityScheme.Designer.cs | 317 +++++++++++++++++ .../20191202142926_CreatingIdentityScheme.cs | 221 ++++++++++++ .../20191202145342_InsertedRoles.Designer.cs | 333 ++++++++++++++++++ .../20191202145342_InsertedRoles.cs | 33 ++ .../ApplicationContextModelSnapshot.cs | 269 ++++++++++++++ .../Models/ApplicationContext.cs | 6 +- .../Models/Configuration/RoleConfiguration.cs | 24 ++ .../IdentityByExamples/Models/User.cs | 10 + .../IdentityByExamples/Startup.cs | 6 + 13 files changed, 1327 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 IdentityByExamples/IdentityByExamples/Migrations/20191202135856_InitialMigration.Designer.cs create mode 100644 IdentityByExamples/IdentityByExamples/Migrations/20191202135856_InitialMigration.cs create mode 100644 IdentityByExamples/IdentityByExamples/Migrations/20191202142926_CreatingIdentityScheme.Designer.cs create mode 100644 IdentityByExamples/IdentityByExamples/Migrations/20191202142926_CreatingIdentityScheme.cs create mode 100644 IdentityByExamples/IdentityByExamples/Migrations/20191202145342_InsertedRoles.Designer.cs create mode 100644 IdentityByExamples/IdentityByExamples/Migrations/20191202145342_InsertedRoles.cs create mode 100644 IdentityByExamples/IdentityByExamples/Models/Configuration/RoleConfiguration.cs create mode 100644 IdentityByExamples/IdentityByExamples/Models/User.cs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1520616 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/IdentityByExamples/.vs +/IdentityByExamples/IdentityByExamples/obj +/IdentityByExamples/IdentityByExamples/bin diff --git a/IdentityByExamples/IdentityByExamples/IdentityByExamples.csproj b/IdentityByExamples/IdentityByExamples/IdentityByExamples.csproj index b1232b9..6131a16 100644 --- a/IdentityByExamples/IdentityByExamples/IdentityByExamples.csproj +++ b/IdentityByExamples/IdentityByExamples/IdentityByExamples.csproj @@ -5,6 +5,7 @@ + diff --git a/IdentityByExamples/IdentityByExamples/Migrations/20191202135856_InitialMigration.Designer.cs b/IdentityByExamples/IdentityByExamples/Migrations/20191202135856_InitialMigration.Designer.cs new file mode 100644 index 0000000..755ccbb --- /dev/null +++ b/IdentityByExamples/IdentityByExamples/Migrations/20191202135856_InitialMigration.Designer.cs @@ -0,0 +1,64 @@ +// +using System; +using IdentityByExamples.Models; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace IdentityByExamples.Migrations +{ + [DbContext(typeof(ApplicationContext))] + [Migration("20191202135856_InitialMigration")] + partial class InitialMigration + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "3.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("IdentityByExamples.Models.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Age") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Position") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Employees"); + + b.HasData( + new + { + Id = new Guid("e310a6cb-6677-4aa6-93c7-2763956f7a97"), + Age = 26, + Name = "Mark Miens", + Position = "Software Developer" + }, + new + { + Id = new Guid("398d10fe-4b8d-4606-8e9c-bd2c78d4e001"), + Age = 29, + Name = "Anna Simmons", + Position = "Software Developer" + }); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/IdentityByExamples/IdentityByExamples/Migrations/20191202135856_InitialMigration.cs b/IdentityByExamples/IdentityByExamples/Migrations/20191202135856_InitialMigration.cs new file mode 100644 index 0000000..f866982 --- /dev/null +++ b/IdentityByExamples/IdentityByExamples/Migrations/20191202135856_InitialMigration.cs @@ -0,0 +1,41 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace IdentityByExamples.Migrations +{ + public partial class InitialMigration : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Employees", + columns: table => new + { + Id = table.Column(nullable: false), + Name = table.Column(nullable: false), + Age = table.Column(nullable: false), + Position = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Employees", x => x.Id); + }); + + migrationBuilder.InsertData( + table: "Employees", + columns: new[] { "Id", "Age", "Name", "Position" }, + values: new object[] { new Guid("e310a6cb-6677-4aa6-93c7-2763956f7a97"), 26, "Mark Miens", "Software Developer" }); + + migrationBuilder.InsertData( + table: "Employees", + columns: new[] { "Id", "Age", "Name", "Position" }, + values: new object[] { new Guid("398d10fe-4b8d-4606-8e9c-bd2c78d4e001"), 29, "Anna Simmons", "Software Developer" }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Employees"); + } + } +} diff --git a/IdentityByExamples/IdentityByExamples/Migrations/20191202142926_CreatingIdentityScheme.Designer.cs b/IdentityByExamples/IdentityByExamples/Migrations/20191202142926_CreatingIdentityScheme.Designer.cs new file mode 100644 index 0000000..15a99dc --- /dev/null +++ b/IdentityByExamples/IdentityByExamples/Migrations/20191202142926_CreatingIdentityScheme.Designer.cs @@ -0,0 +1,317 @@ +// +using System; +using IdentityByExamples.Models; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace IdentityByExamples.Migrations +{ + [DbContext(typeof(ApplicationContext))] + [Migration("20191202142926_CreatingIdentityScheme")] + partial class CreatingIdentityScheme + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "3.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("IdentityByExamples.Models.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Age") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Position") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Employees"); + + b.HasData( + new + { + Id = new Guid("e310a6cb-6677-4aa6-93c7-2763956f7a97"), + Age = 26, + Name = "Mark Miens", + Position = "Software Developer" + }, + new + { + Id = new Guid("398d10fe-4b8d-4606-8e9c-bd2c78d4e001"), + Age = 29, + Name = "Anna Simmons", + Position = "Software Developer" + }); + }); + + modelBuilder.Entity("IdentityByExamples.Models.User", 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("FirstName") + .HasColumnType("nvarchar(max)"); + + b.Property("LastName") + .HasColumnType("nvarchar(max)"); + + 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.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("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.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.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.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(450)"); + + b.Property("ProviderKey") + .HasColumnType("nvarchar(450)"); + + 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(450)"); + + b.Property("Name") + .HasColumnType("nvarchar(450)"); + + 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("IdentityByExamples.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("IdentityByExamples.Models.User", 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("IdentityByExamples.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("IdentityByExamples.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/IdentityByExamples/IdentityByExamples/Migrations/20191202142926_CreatingIdentityScheme.cs b/IdentityByExamples/IdentityByExamples/Migrations/20191202142926_CreatingIdentityScheme.cs new file mode 100644 index 0000000..8d249e2 --- /dev/null +++ b/IdentityByExamples/IdentityByExamples/Migrations/20191202142926_CreatingIdentityScheme.cs @@ -0,0 +1,221 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace IdentityByExamples.Migrations +{ + public partial class CreatingIdentityScheme : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "AspNetRoles", + columns: table => new + { + Id = table.Column(nullable: false), + Name = table.Column(maxLength: 256, nullable: true), + NormalizedName = table.Column(maxLength: 256, nullable: true), + ConcurrencyStamp = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetRoles", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "AspNetUsers", + columns: table => new + { + Id = table.Column(nullable: false), + UserName = table.Column(maxLength: 256, nullable: true), + NormalizedUserName = table.Column(maxLength: 256, nullable: true), + Email = table.Column(maxLength: 256, nullable: true), + NormalizedEmail = table.Column(maxLength: 256, nullable: true), + EmailConfirmed = table.Column(nullable: false), + PasswordHash = table.Column(nullable: true), + SecurityStamp = table.Column(nullable: true), + ConcurrencyStamp = table.Column(nullable: true), + PhoneNumber = table.Column(nullable: true), + PhoneNumberConfirmed = table.Column(nullable: false), + TwoFactorEnabled = table.Column(nullable: false), + LockoutEnd = table.Column(nullable: true), + LockoutEnabled = table.Column(nullable: false), + AccessFailedCount = table.Column(nullable: false), + FirstName = table.Column(nullable: true), + LastName = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUsers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "AspNetRoleClaims", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + RoleId = table.Column(nullable: false), + ClaimType = table.Column(nullable: true), + ClaimValue = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id); + table.ForeignKey( + name: "FK_AspNetRoleClaims_AspNetRoles_RoleId", + column: x => x.RoleId, + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserClaims", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + UserId = table.Column(nullable: false), + ClaimType = table.Column(nullable: true), + ClaimValue = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserClaims", x => x.Id); + table.ForeignKey( + name: "FK_AspNetUserClaims_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserLogins", + columns: table => new + { + LoginProvider = table.Column(nullable: false), + ProviderKey = table.Column(nullable: false), + ProviderDisplayName = table.Column(nullable: true), + UserId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey }); + table.ForeignKey( + name: "FK_AspNetUserLogins_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserRoles", + columns: table => new + { + UserId = table.Column(nullable: false), + RoleId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId }); + table.ForeignKey( + name: "FK_AspNetUserRoles_AspNetRoles_RoleId", + column: x => x.RoleId, + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_AspNetUserRoles_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserTokens", + columns: table => new + { + UserId = table.Column(nullable: false), + LoginProvider = table.Column(nullable: false), + Name = table.Column(nullable: false), + Value = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); + table.ForeignKey( + name: "FK_AspNetUserTokens_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_AspNetRoleClaims_RoleId", + table: "AspNetRoleClaims", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "RoleNameIndex", + table: "AspNetRoles", + column: "NormalizedName", + unique: true, + filter: "[NormalizedName] IS NOT NULL"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserClaims_UserId", + table: "AspNetUserClaims", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserLogins_UserId", + table: "AspNetUserLogins", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserRoles_RoleId", + table: "AspNetUserRoles", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "EmailIndex", + table: "AspNetUsers", + column: "NormalizedEmail"); + + migrationBuilder.CreateIndex( + name: "UserNameIndex", + table: "AspNetUsers", + column: "NormalizedUserName", + unique: true, + filter: "[NormalizedUserName] IS NOT NULL"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "AspNetRoleClaims"); + + migrationBuilder.DropTable( + name: "AspNetUserClaims"); + + migrationBuilder.DropTable( + name: "AspNetUserLogins"); + + migrationBuilder.DropTable( + name: "AspNetUserRoles"); + + migrationBuilder.DropTable( + name: "AspNetUserTokens"); + + migrationBuilder.DropTable( + name: "AspNetRoles"); + + migrationBuilder.DropTable( + name: "AspNetUsers"); + } + } +} diff --git a/IdentityByExamples/IdentityByExamples/Migrations/20191202145342_InsertedRoles.Designer.cs b/IdentityByExamples/IdentityByExamples/Migrations/20191202145342_InsertedRoles.Designer.cs new file mode 100644 index 0000000..e012464 --- /dev/null +++ b/IdentityByExamples/IdentityByExamples/Migrations/20191202145342_InsertedRoles.Designer.cs @@ -0,0 +1,333 @@ +// +using System; +using IdentityByExamples.Models; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace IdentityByExamples.Migrations +{ + [DbContext(typeof(ApplicationContext))] + [Migration("20191202145342_InsertedRoles")] + partial class InsertedRoles + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "3.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("IdentityByExamples.Models.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("Age") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Position") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Employees"); + + b.HasData( + new + { + Id = new Guid("e310a6cb-6677-4aa6-93c7-2763956f7a97"), + Age = 26, + Name = "Mark Miens", + Position = "Software Developer" + }, + new + { + Id = new Guid("398d10fe-4b8d-4606-8e9c-bd2c78d4e001"), + Age = 29, + Name = "Anna Simmons", + Position = "Software Developer" + }); + }); + + modelBuilder.Entity("IdentityByExamples.Models.User", 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("FirstName") + .HasColumnType("nvarchar(max)"); + + b.Property("LastName") + .HasColumnType("nvarchar(max)"); + + 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.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"); + + b.HasData( + new + { + Id = "5e0246f5-e1b9-46ba-867e-81d1917aaaf7", + ConcurrencyStamp = "1dee1e04-abee-43db-b5d7-69c719165b88", + Name = "Visitor", + NormalizedName = "VISITOR" + }, + new + { + Id = "be7b6b91-2662-4760-8ee1-d966075e524e", + ConcurrencyStamp = "84ff6b93-365d-454a-b810-8bbe8d206491", + Name = "Administrator", + NormalizedName = "ADMINISTRATOR" + }); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.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.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.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(450)"); + + b.Property("ProviderKey") + .HasColumnType("nvarchar(450)"); + + 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(450)"); + + b.Property("Name") + .HasColumnType("nvarchar(450)"); + + 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("IdentityByExamples.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("IdentityByExamples.Models.User", 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("IdentityByExamples.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("IdentityByExamples.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/IdentityByExamples/IdentityByExamples/Migrations/20191202145342_InsertedRoles.cs b/IdentityByExamples/IdentityByExamples/Migrations/20191202145342_InsertedRoles.cs new file mode 100644 index 0000000..b720cc9 --- /dev/null +++ b/IdentityByExamples/IdentityByExamples/Migrations/20191202145342_InsertedRoles.cs @@ -0,0 +1,33 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace IdentityByExamples.Migrations +{ + public partial class InsertedRoles : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.InsertData( + table: "AspNetRoles", + columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" }, + values: new object[] { "5e0246f5-e1b9-46ba-867e-81d1917aaaf7", "1dee1e04-abee-43db-b5d7-69c719165b88", "Visitor", "VISITOR" }); + + migrationBuilder.InsertData( + table: "AspNetRoles", + columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" }, + values: new object[] { "be7b6b91-2662-4760-8ee1-d966075e524e", "84ff6b93-365d-454a-b810-8bbe8d206491", "Administrator", "ADMINISTRATOR" }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DeleteData( + table: "AspNetRoles", + keyColumn: "Id", + keyValue: "5e0246f5-e1b9-46ba-867e-81d1917aaaf7"); + + migrationBuilder.DeleteData( + table: "AspNetRoles", + keyColumn: "Id", + keyValue: "be7b6b91-2662-4760-8ee1-d966075e524e"); + } + } +} diff --git a/IdentityByExamples/IdentityByExamples/Migrations/ApplicationContextModelSnapshot.cs b/IdentityByExamples/IdentityByExamples/Migrations/ApplicationContextModelSnapshot.cs index 4744892..81f0f60 100644 --- a/IdentityByExamples/IdentityByExamples/Migrations/ApplicationContextModelSnapshot.cs +++ b/IdentityByExamples/IdentityByExamples/Migrations/ApplicationContextModelSnapshot.cs @@ -56,6 +56,275 @@ protected override void BuildModel(ModelBuilder modelBuilder) Position = "Software Developer" }); }); + + modelBuilder.Entity("IdentityByExamples.Models.User", 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("FirstName") + .HasColumnType("nvarchar(max)"); + + b.Property("LastName") + .HasColumnType("nvarchar(max)"); + + 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.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"); + + b.HasData( + new + { + Id = "5e0246f5-e1b9-46ba-867e-81d1917aaaf7", + ConcurrencyStamp = "1dee1e04-abee-43db-b5d7-69c719165b88", + Name = "Visitor", + NormalizedName = "VISITOR" + }, + new + { + Id = "be7b6b91-2662-4760-8ee1-d966075e524e", + ConcurrencyStamp = "84ff6b93-365d-454a-b810-8bbe8d206491", + Name = "Administrator", + NormalizedName = "ADMINISTRATOR" + }); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.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.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.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(450)"); + + b.Property("ProviderKey") + .HasColumnType("nvarchar(450)"); + + 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(450)"); + + b.Property("Name") + .HasColumnType("nvarchar(450)"); + + 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("IdentityByExamples.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("IdentityByExamples.Models.User", 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("IdentityByExamples.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("IdentityByExamples.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); #pragma warning restore 612, 618 } } diff --git a/IdentityByExamples/IdentityByExamples/Models/ApplicationContext.cs b/IdentityByExamples/IdentityByExamples/Models/ApplicationContext.cs index 40cf9a9..1009810 100644 --- a/IdentityByExamples/IdentityByExamples/Models/ApplicationContext.cs +++ b/IdentityByExamples/IdentityByExamples/Models/ApplicationContext.cs @@ -1,9 +1,10 @@ using IdentityByExamples.Models.Configuration; +using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; namespace IdentityByExamples.Models { - public class ApplicationContext : DbContext + public class ApplicationContext : IdentityDbContext { public ApplicationContext(DbContextOptions options) : base(options) @@ -12,7 +13,10 @@ public ApplicationContext(DbContextOptions options) protected override void OnModelCreating(ModelBuilder modelBuilder) { + base.OnModelCreating(modelBuilder); + modelBuilder.ApplyConfiguration(new EmployeeConfiguration()); + modelBuilder.ApplyConfiguration(new RoleConfiguration()); } public DbSet Employees { get; set; } diff --git a/IdentityByExamples/IdentityByExamples/Models/Configuration/RoleConfiguration.cs b/IdentityByExamples/IdentityByExamples/Models/Configuration/RoleConfiguration.cs new file mode 100644 index 0000000..47a5a9f --- /dev/null +++ b/IdentityByExamples/IdentityByExamples/Models/Configuration/RoleConfiguration.cs @@ -0,0 +1,24 @@ +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace IdentityByExamples.Models.Configuration +{ + public class RoleConfiguration : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + builder.HasData( + new IdentityRole + { + Name = "Visitor", + NormalizedName = "VISITOR" + }, + new IdentityRole + { + Name = "Administrator", + NormalizedName = "ADMINISTRATOR" + }); + } + } +} diff --git a/IdentityByExamples/IdentityByExamples/Models/User.cs b/IdentityByExamples/IdentityByExamples/Models/User.cs new file mode 100644 index 0000000..68dccfd --- /dev/null +++ b/IdentityByExamples/IdentityByExamples/Models/User.cs @@ -0,0 +1,10 @@ +using Microsoft.AspNetCore.Identity; + +namespace IdentityByExamples.Models +{ + public class User : IdentityUser + { + public string FirstName { get; set; } + public string LastName { get; set; } + } +} diff --git a/IdentityByExamples/IdentityByExamples/Startup.cs b/IdentityByExamples/IdentityByExamples/Startup.cs index 2e70a61..dc931c4 100644 --- a/IdentityByExamples/IdentityByExamples/Startup.cs +++ b/IdentityByExamples/IdentityByExamples/Startup.cs @@ -6,6 +6,8 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.HttpsPolicy; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -28,6 +30,10 @@ public void ConfigureServices(IServiceCollection services) services.AddDbContext(opts => opts.UseSqlServer(Configuration.GetConnectionString("sqlConnection"))); + services.AddIdentity() + .AddEntityFrameworkStores(); + + services.AddControllersWithViews(); } From c28109054b3a2b0dc0fc81ba193ae8cee8b89fe8 Mon Sep 17 00:00:00 2001 From: Marinko Date: Sat, 25 Jul 2020 13:28:32 +0200 Subject: [PATCH 2/2] Removed duplicated migration files --- ...0191202102202_InitialMigration.Designer.cs | 64 ------------------- .../20191202102202_InitialMigration.cs | 41 ------------ 2 files changed, 105 deletions(-) delete mode 100644 IdentityByExamples/IdentityByExamples/Migrations/20191202102202_InitialMigration.Designer.cs delete mode 100644 IdentityByExamples/IdentityByExamples/Migrations/20191202102202_InitialMigration.cs diff --git a/IdentityByExamples/IdentityByExamples/Migrations/20191202102202_InitialMigration.Designer.cs b/IdentityByExamples/IdentityByExamples/Migrations/20191202102202_InitialMigration.Designer.cs deleted file mode 100644 index 27c8f52..0000000 --- a/IdentityByExamples/IdentityByExamples/Migrations/20191202102202_InitialMigration.Designer.cs +++ /dev/null @@ -1,64 +0,0 @@ -// -using System; -using IdentityByExamples.Models; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -namespace IdentityByExamples.Migrations -{ - [DbContext(typeof(ApplicationContext))] - [Migration("20191202102202_InitialMigration")] - partial class InitialMigration - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "3.0.1") - .HasAnnotation("Relational:MaxIdentifierLength", 128) - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - modelBuilder.Entity("IdentityByExamples.Models.Employee", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); - - b.Property("Age") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Position") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Employees"); - - b.HasData( - new - { - Id = new Guid("e310a6cb-6677-4aa6-93c7-2763956f7a97"), - Age = 26, - Name = "Mark Miens", - Position = "Software Developer" - }, - new - { - Id = new Guid("398d10fe-4b8d-4606-8e9c-bd2c78d4e001"), - Age = 29, - Name = "Anna Simmons", - Position = "Software Developer" - }); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/IdentityByExamples/IdentityByExamples/Migrations/20191202102202_InitialMigration.cs b/IdentityByExamples/IdentityByExamples/Migrations/20191202102202_InitialMigration.cs deleted file mode 100644 index f866982..0000000 --- a/IdentityByExamples/IdentityByExamples/Migrations/20191202102202_InitialMigration.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -namespace IdentityByExamples.Migrations -{ - public partial class InitialMigration : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Employees", - columns: table => new - { - Id = table.Column(nullable: false), - Name = table.Column(nullable: false), - Age = table.Column(nullable: false), - Position = table.Column(nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Employees", x => x.Id); - }); - - migrationBuilder.InsertData( - table: "Employees", - columns: new[] { "Id", "Age", "Name", "Position" }, - values: new object[] { new Guid("e310a6cb-6677-4aa6-93c7-2763956f7a97"), 26, "Mark Miens", "Software Developer" }); - - migrationBuilder.InsertData( - table: "Employees", - columns: new[] { "Id", "Age", "Name", "Position" }, - values: new object[] { new Guid("398d10fe-4b8d-4606-8e9c-bd2c78d4e001"), 29, "Anna Simmons", "Software Developer" }); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Employees"); - } - } -}