Hello all,
Kindly please, I am new to C# and Asp.Net Core and have spent a consistent month coding a simple role--based identity system.
I have built my Model classes, UserStore and created a Migration, done the update all without any error(s). But for the sake of my life, I cannot get over a StackOverflow exception to go away when attempting to send my Employee instance to the Database from web form. I also haven't found an hint on here nor on StackOverflow (No pun intended) that suggests the solution to my problem. I've been having this challenge for about a week now. Please kindly help point me in the right direction. Please see log tail below:
juwonlona@Luvv0n:~/Nextekk$ dotnet run
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
User profile is available. Using '/home/juwonlona/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.
Hosting environment: Development
Content root path: /home/juwonlona/Nextekk
Now listening on: https://localhost:5001
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET https://localhost:5001/
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
Executing endpoint 'Page: /Index'
info: Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker[3]
Route matched with {page = "/Index"}. Executing page /Index
info: Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker[101]
Executing handler method Nextekk.Pages.IndexModel.OnGet - ModelState is Valid
info: Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker[102]
Executed handler method OnGet, returned result .
info: Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker[103]
Executing an implicit handler method - ModelState is Valid
info: Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker[104]
Executed an implicit handler method, returned result Microsoft.AspNetCore.Mvc.RazorPages.PageResult.
info: Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker[4]
Executed page /Index in 205.5814ms
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
Executed endpoint 'Page: /Index'
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 381.5546ms 200 text/html; charset=utf-8
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET https://localhost:5001/lib/bootstrap/dist/css/bootstrap.css
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET https://localhost:5001/css/site.css
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET https://localhost:5001/lib/bootstrap/dist/js/bootstrap.bundle.js
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET https://localhost:5001/js/site.js?v=dLGP40S79Xnx6GqUthRF6NWvjvhQ1nOvdVSwaNcgG18
info: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[2]
Sending file. Request path: '/js/site.js'. Physical path: '/home/juwonlona/Nextekk/wwwroot/js/site.js'
info: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[2]
Sending file. Request path: '/css/site.css'. Physical path: '/home/juwonlona/Nextekk/wwwroot/css/site.css'
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 18.6266ms 200 text/css
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 6.4199ms 200 application/javascript
info: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[2]
Sending file. Request path: '/lib/bootstrap/dist/css/bootstrap.css'. Physical path: '/home/juwonlona/Nextekk/wwwroot/lib/bootstrap/dist/css/bootstrap.css'
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 117.7394ms 200 text/css
info: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[2]
Sending file. Request path: '/lib/bootstrap/dist/js/bootstrap.bundle.js'. Physical path: '/home/juwonlona/Nextekk/wwwroot/lib/bootstrap/dist/js/bootstrap.bundle.js'
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 72.6724ms 200 application/javascript
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET https://localhost:5001/lib/jquery/dist/jquery.js
info: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[6]
The file /lib/jquery/dist/jquery.js was not modified
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 8.7395ms 304 application/javascript
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET https://localhost:5001/favicon.ico
info: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[2]
Sending file. Request path: '/favicon.ico'. Physical path: '/home/juwonlona/Nextekk/wwwroot/favicon.ico'
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 14.8927ms 200 image/x-icon
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET https://localhost:5001/admin/
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
Executing endpoint 'Page: /Admin/Index'
info: Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker[3]
Route matched with {page = "/Admin/Index"}. Executing page /Admin/Index
info: Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker[101]
Executing handler method Nextekk.Pages.Admin.IndexModel.OnGetAsync - ModelState is Valid
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
Entity Framework Core 2.2.6-servicing-10079 initialized 'NextekkDBContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer' with options: None
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (59ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT [e].[Id], [e].[Dob], [e].[Email], [e].[FirstName], [e].[IsAdmin], [e].[LastName], [e].[NoOfChildren], [e].[OtherInfoId], [e].[Password], [e].[PasswordHash], [e].[PhoneNumber], [e].[PhoneNumberConfirmed], [e].[SecurityStamp], [e].[UserName]
FROM [Employee] AS [e]
info: Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker[102]
Executed handler method OnGetAsync, returned result .
info: Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker[103]
Executing an implicit handler method - ModelState is Valid
info: Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker[104]
Executed an implicit handler method, returned result Microsoft.AspNetCore.Mvc.RazorPages.PageResult.
info: Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker[4]
Executed page /Admin/Index in 1035.6315ms
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
Executed endpoint 'Page: /Admin/Index'
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 1063.8175ms 200 text/html; charset=utf-8
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET https://localhost:5001/lib/bootstrap/dist/js/bootstrap.bundle.js
info: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[6]
The file /lib/bootstrap/dist/js/bootstrap.bundle.js was not modified
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 0.4123ms 304 application/javascript
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET https://localhost:5001/js/site.js?v=dLGP40S79Xnx6GqUthRF6NWvjvhQ1nOvdVSwaNcgG18
info: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[2]
Sending file. Request path: '/js/site.js'. Physical path: '/home/juwonlona/Nextekk/wwwroot/js/site.js'
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 0.6329ms 200 application/javascript
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET https://localhost:5001/Admin/Create
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
Executing endpoint 'Page: /Admin/Create'
info: Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker[3]
Route matched with {page = "/Admin/Create"}. Executing page /Admin/Create
info: Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker[101]
Executing handler method Nextekk.Pages.Admin.CreateModel.OnGet - ModelState is Valid
info: Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker[102]
Executed handler method OnGet, returned result Microsoft.AspNetCore.Mvc.RazorPages.PageResult.
info: Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker[4]
Executed page /Admin/Create in 172.3785ms
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
Executed endpoint 'Page: /Admin/Create'
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 261.9325ms 200 text/html; charset=utf-8
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET https://localhost:5001/lib/jquery-validation/dist/jquery.validate.js
info: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[2]
Sending file. Request path: '/lib/jquery-validation/dist/jquery.validate.js'. Physical path: '/home/juwonlona/Nextekk/wwwroot/lib/jquery-validation/dist/jquery.validate.js'
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 21.9815ms 200 application/javascript
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET https://localhost:5001/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js
info: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[2]
Sending file. Request path: '/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js'. Physical path: '/home/juwonlona/Nextekk/wwwroot/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js'
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 29.694ms 200 application/javascript
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 POST https://localhost:5001/Admin/Create application/x-www-form-urlencoded 502
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
Executing endpoint 'Page: /Admin/Create'
info: Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker[3]
Route matched with {page = "/Admin/Create"}. Executing page /Admin/Create
Process is terminating due to StackOverflowException.
For dotnet run
-->
EF Core version:
Database provider: (Microsoft.EntityFrameworkCore.SqlServer)
Target framework: (e.g. .NET Core 2.2)
Operating system: Linux Ubuntu 16.04
IDE: (e.g. Visual Studio code 2017)
@flownsa There is nothing obvious here. Can you attach a small, runnable project that reproduces issue so that we can investigate?
@ajcvickers Thank you very much sir. If its okay to upload my files here is my entire code attached as zip.
Also, for quick reference, here is my DBContext, Migration code and Employee classes, all inherited from Identity.
Employee class
```C#
using System;
using System.Collections;
using System.Collections.Generic;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.Security.Claims;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.AspNetCore.Mvc.ModelBinding;
namespace Nextekk.Models
{
[Table("Employee")]
public partial class Employee : IdentityUser
{
// The role name this employee belong to
// private static int IdSeed = 5000;
public bool IsAdmin
{
get
{
return IsAdmin;
}
private set{}
}
public Employee() // assign default identity id and set default admin value
{
// IdSeed++;
// EmployeeId = IdSeed.ToString();
IsAdmin = false;
// EmployeeId = Id;
}
// public string Id {get{return Id;} private set {employee();} } // does not return elmployeeid only accessible through db tables
[Required]
[StringLength(50)]
public string FirstName { get; set; }
[Required]
[StringLength(50)]
public string LastName { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{dd-mm-yyyy}", ApplyFormatInEditMode = true)]
public DateTime? Dob { get; set; }
// public enum Sex { Female=1, Male=0 }
// public enum MaritalStatus { Single, Married, Divorced, Seperated};
[Required]
public string Password { get; set; }
// [Range(0, 30)]
public int NoOfChildren { get; set; }
// Navigational properties
// public virtual ICollection
// public virtual ICollection
// public virtual ICollection
// public virtual ICollection
public virtual OtherInfo OtherInfo { get; set; } // reference to added user information
public virtual ICollection
}
}
// An operation was scaffolded that may result in the loss of data. Please review the migration for accuracy.
**DBContext**
```C#
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
namespace Nextekk.Models
{
public class NextekkDBContext: IdentityDbContext<Employee, Role, string>
// IdentityUserClaim<string>, ApplicationUserRole, IdentityUserLogin<string>,
// IdentityRoleClaim<string>, IdentityUserToken<string>>
{
public NextekkDBContext(DbContextOptions<NextekkDBContext> options)
: base(options)
{
}
public virtual DbSet<Employee> Employees { get; set; }
public DbSet<IdentityUserClaim<string>> IdentityUserClaims { get; set; }
public virtual DbSet<Role> Role { get; set; }
// public virtual DbSet<OtherInfo> OtherInfo { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasAnnotation("ProductVersion", "2.2.6-servicing-10079");
base.OnModelCreating(modelBuilder);
// modelBuilder.Entity<Role>(entity => entity.ToTable(name:"Role"));
// modelBuilder.Entity<IdentityUserRole<string>>(entity => entity.ToTable(name:"EmployeeRole"));
// modelBuilder.Ignore <IdentityUserLogin<string>>();
// passes type Employee to create table with
modelBuilder.Entity<Employee>(entity =>
{
entity.ToTable(name:"Employee");
// To unbind unused derived identity properties
// entity.Ignore(ignore => ignore.Id);
// entity.Property(e => e.Id)
// .entity.ValueGeneratedNever();
entity.Ignore(ignore => ignore.ConcurrencyStamp);
entity.Ignore(ignore => ignore.NormalizedUserName);
entity.Ignore(ignore => ignore.EmailConfirmed);
entity.Ignore(ignore => ignore.NormalizedEmail);
// entity.Ignore(ignore => ignore.PasswordHash);
// entity.Ignore(ignore => ignore.SecurityStamp);
// entity.Ignore(ignore => ignore.PhoneNumberConfirmed);
entity.Ignore(ignore => ignore.TwoFactorEnabled);
entity.Ignore(ignore => ignore.LockoutEnd);
entity.Ignore(ignore => ignore.LockoutEnabled);
entity.Ignore(ignore => ignore.AccessFailedCount);
// entity.HasIndex(e => e.UserName).IsUnique();
entity.Property(e => e.FirstName).IsRequired().HasMaxLength(100);
entity.Property(e => e.LastName).IsRequired().HasMaxLength(100);
entity.Property(e => e.Dob).HasColumnType("date");
// entity.HasMany(e => e.Claims).WithOne().HasForeignKey(fk => fk.UserId).IsRequired();
// entity.HasMany(e => e.EmployeeRole).WithOne().HasForeignKey(fk => fk.EmployeeId);
// entity.HasMany(e => e.Role).WithOne().HasForeignKey(fk => fk.EmployeeId);
// entity.HasOne(e => e.OtherInfo).WithOne().HasForeignKey(fk => fk.EmployeeId).IsRequired();
});
modelBuilder.Entity<OtherInfo>(entity =>
{
entity.HasKey(e => e.Id);
entity.Property(e => e.Id).ValueGeneratedNever();
entity.Property(e => e.DateJoined).HasColumnType("date");
entity.Property(e => e.DatePromoted).HasColumnType("date");
entity.Property(e => e.MaxEdu).HasMaxLength(50).IsUnicode(false);
entity.Property(e => e.Position).HasMaxLength(50).IsUnicode(false);
entity.Property(e => e.Salary).HasColumnType("decimal(10, 2)");
entity.Property(e => e.School).HasMaxLength(250).IsUnicode(false);
entity.Property(e => e.TimeServed).HasColumnType("date");
// entity.HasOne(e => e.EmployeeId).WithOne(p => p.Employee).HasForeignKey<OtherInfo>(d => d.EmployeeId)
// .OnDelete(DeleteBehavior.ClientSetNull)
// .HasConstraintName("FK_OtherInfoEmployee");
});
// modelBuilder.Entity<EmployeeRole>(entity =>
// {
// entity.ToTable(name:"EmployeeRole");
// //
// });
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
// #warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings.
// optionsBuilder.UseSqlServer("Server=localhost;Database=NextekkDB;User Id=****;Password=********");
}
}
}
}
My Migration code
Migration
```C#
using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Nextekk.Migrations
{
public partial class FirstCreated : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "OtherInfo",
columns: table => new
{
Id = table.Column<string>(nullable: false),
Activated = table.Column<bool>(nullable: false),
DateJoined = table.Column<DateTime>(type: "date", nullable: true),
MaxEdu = table.Column<string>(unicode: false, maxLength: 50, nullable: true),
School = table.Column<string>(unicode: false, maxLength: 250, nullable: true),
TimeServed = table.Column<DateTime>(type: "date", nullable: true),
Position = table.Column<string>(unicode: false, maxLength: 50, nullable: true),
DatePromoted = table.Column<DateTime>(type: "date", nullable: true),
Salary = table.Column<decimal>(type: "decimal(10, 2)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_OtherInfo", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Employee",
columns: table => new
{
Id = table.Column<string>(nullable: false),
UserName = table.Column<string>(maxLength: 256, nullable: true),
Email = table.Column<string>(maxLength: 256, nullable: true),
PasswordHash = table.Column<string>(nullable: true),
SecurityStamp = table.Column<string>(nullable: true),
PhoneNumber = table.Column<string>(nullable: true),
PhoneNumberConfirmed = table.Column<bool>(nullable: false),
IsAdmin = table.Column<bool>(nullable: false),
FirstName = table.Column<string>(maxLength: 100, nullable: false),
LastName = table.Column<string>(maxLength: 100, nullable: false),
Dob = table.Column<DateTime>(type: "date", nullable: true),
Password = table.Column<string>(nullable: false),
NoOfChildren = table.Column<int>(nullable: false),
OtherInfoId = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Employee", x => x.Id);
table.ForeignKey(
name: "FK_Employee_OtherInfo_OtherInfoId",
column: x => x.OtherInfoId,
principalTable: "OtherInfo",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "AspNetUserClaims",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
UserId = table.Column<string>(nullable: false),
ClaimType = table.Column<string>(nullable: true),
ClaimValue = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserClaims", x => x.Id);
table.ForeignKey(
name: "FK_AspNetUserClaims_Employee_UserId",
column: x => x.UserId,
principalTable: "Employee",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AspNetUserLogins",
columns: table => new
{
LoginProvider = table.Column<string>(nullable: false),
ProviderKey = table.Column<string>(nullable: false),
ProviderDisplayName = table.Column<string>(nullable: true),
UserId = table.Column<string>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey });
table.ForeignKey(
name: "FK_AspNetUserLogins_Employee_UserId",
column: x => x.UserId,
principalTable: "Employee",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AspNetUserTokens",
columns: table => new
{
UserId = table.Column<string>(nullable: false),
LoginProvider = table.Column<string>(nullable: false),
Name = table.Column<string>(nullable: false),
Value = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name });
table.ForeignKey(
name: "FK_AspNetUserTokens_Employee_UserId",
column: x => x.UserId,
principalTable: "Employee",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Role",
columns: table => new
{
Id = table.Column<string>(nullable: false),
Name = table.Column<string>(maxLength: 256, nullable: true),
NormalizedName = table.Column<string>(maxLength: 256, nullable: true),
ConcurrencyStamp = table.Column<string>(nullable: true),
EmployeeId = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Role", x => x.Id);
table.ForeignKey(
name: "FK_Role_Employee_EmployeeId",
column: x => x.EmployeeId,
principalTable: "Employee",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "AspNetRoleClaims",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
RoleId = table.Column<string>(nullable: false),
ClaimType = table.Column<string>(nullable: true),
ClaimValue = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id);
table.ForeignKey(
name: "FK_AspNetRoleClaims_Role_RoleId",
column: x => x.RoleId,
principalTable: "Role",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "EmployeeRole",
columns: table => new
{
UserId = table.Column<string>(nullable: false),
RoleId = table.Column<string>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_EmployeeRole", x => new { x.UserId, x.RoleId });
table.ForeignKey(
name: "FK_EmployeeRole_Role_RoleId",
column: x => x.RoleId,
principalTable: "Role",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_EmployeeRole_Employee_UserId",
column: x => x.UserId,
principalTable: "Employee",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_AspNetRoleClaims_RoleId",
table: "AspNetRoleClaims",
column: "RoleId");
migrationBuilder.CreateIndex(
name: "IX_AspNetUserClaims_UserId",
table: "AspNetUserClaims",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_AspNetUserLogins_UserId",
table: "AspNetUserLogins",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_Employee_OtherInfoId",
table: "Employee",
column: "OtherInfoId");
migrationBuilder.CreateIndex(
name: "IX_EmployeeRole_RoleId",
table: "EmployeeRole",
column: "RoleId");
migrationBuilder.CreateIndex(
name: "IX_Role_EmployeeId",
table: "Role",
column: "EmployeeId");
migrationBuilder.CreateIndex(
name: "RoleNameIndex",
table: "Role",
column: "NormalizedName",
unique: true,
filter: "[NormalizedName] IS NOT NULL");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "AspNetRoleClaims");
migrationBuilder.DropTable(
name: "AspNetUserClaims");
migrationBuilder.DropTable(
name: "AspNetUserLogins");
migrationBuilder.DropTable(
name: "AspNetUserTokens");
migrationBuilder.DropTable(
name: "EmployeeRole");
migrationBuilder.DropTable(
name: "Role");
migrationBuilder.DropTable(
name: "Employee");
migrationBuilder.DropTable(
name: "OtherInfo");
}
}
}
```
@flownsa Calling this getter results in an infinite loop, since it simply calls itself:
C#
public bool IsAdmin
{
get
{
return IsAdmin;
}
private set{}
}
Most helpful comment
@flownsa Calling this getter results in an infinite loop, since it simply calls itself:
C# public bool IsAdmin { get { return IsAdmin; } private set{} }