From 4c53e6ab67951bb3e2673d0f4fa850b105697c9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Wed, 21 Dec 2016 22:21:59 +0300 Subject: [PATCH] Created initial IdentityDbContext --- Volo.Abp.sln | 7 + .../Properties/AssemblyInfo.cs | 19 +++ ...olo.Abp.Identity.EntityFrameworkCore.xproj | 20 +++ .../EntityFrameworkCore/IdentityDbContext.cs | 135 ++++++++++++++++++ .../project.json | 16 +++ 5 files changed, 197 insertions(+) create mode 100644 src/Volo.Abp.Identity.EntityFrameworkCore/Properties/AssemblyInfo.cs create mode 100644 src/Volo.Abp.Identity.EntityFrameworkCore/Volo.Abp.Identity.EntityFrameworkCore.xproj create mode 100644 src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityDbContext.cs create mode 100644 src/Volo.Abp.Identity.EntityFrameworkCore/project.json diff --git a/Volo.Abp.sln b/Volo.Abp.sln index 5a35046ad3..4cb5402a6e 100644 --- a/Volo.Abp.sln +++ b/Volo.Abp.sln @@ -80,6 +80,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Volo.Abp.Identity", "src\Vo EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Abp.Identity", "Abp.Identity", "{146F561E-C7B8-4166-9383-47E1BC1A2E62}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Volo.Abp.Identity.EntityFrameworkCore", "src\Volo.Abp.Identity.EntityFrameworkCore\Volo.Abp.Identity.EntityFrameworkCore.xproj", "{439DFC0F-1BA2-464F-900E-EA7E18C08975}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -190,6 +192,10 @@ Global {17DBB40A-243E-41F7-A672-FA316ECB1E33}.Debug|Any CPU.Build.0 = Debug|Any CPU {17DBB40A-243E-41F7-A672-FA316ECB1E33}.Release|Any CPU.ActiveCfg = Release|Any CPU {17DBB40A-243E-41F7-A672-FA316ECB1E33}.Release|Any CPU.Build.0 = Release|Any CPU + {439DFC0F-1BA2-464F-900E-EA7E18C08975}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {439DFC0F-1BA2-464F-900E-EA7E18C08975}.Debug|Any CPU.Build.0 = Debug|Any CPU + {439DFC0F-1BA2-464F-900E-EA7E18C08975}.Release|Any CPU.ActiveCfg = Release|Any CPU + {439DFC0F-1BA2-464F-900E-EA7E18C08975}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -229,5 +235,6 @@ Global {1895A5C9-50D4-4568-9A3A-14657E615A5E} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} {17DBB40A-243E-41F7-A672-FA316ECB1E33} = {1895A5C9-50D4-4568-9A3A-14657E615A5E} {146F561E-C7B8-4166-9383-47E1BC1A2E62} = {447C8A77-E5F0-4538-8687-7383196D04EA} + {439DFC0F-1BA2-464F-900E-EA7E18C08975} = {1895A5C9-50D4-4568-9A3A-14657E615A5E} EndGlobalSection EndGlobal diff --git a/src/Volo.Abp.Identity.EntityFrameworkCore/Properties/AssemblyInfo.cs b/src/Volo.Abp.Identity.EntityFrameworkCore/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..953262cd6a --- /dev/null +++ b/src/Volo.Abp.Identity.EntityFrameworkCore/Properties/AssemblyInfo.cs @@ -0,0 +1,19 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Volo.Abp.Identity.EntityFrameworkCore")] +[assembly: AssemblyTrademark("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("439dfc0f-1ba2-464f-900e-ea7e18c08975")] diff --git a/src/Volo.Abp.Identity.EntityFrameworkCore/Volo.Abp.Identity.EntityFrameworkCore.xproj b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo.Abp.Identity.EntityFrameworkCore.xproj new file mode 100644 index 0000000000..4513a5b097 --- /dev/null +++ b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo.Abp.Identity.EntityFrameworkCore.xproj @@ -0,0 +1,20 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 439dfc0f-1ba2-464f-900e-ea7e18c08975 + + + .\obj + .\bin\ + v4.6.1 + + + 2.0 + + + \ No newline at end of file diff --git a/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityDbContext.cs b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityDbContext.cs new file mode 100644 index 0000000000..630702b1fc --- /dev/null +++ b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityDbContext.cs @@ -0,0 +1,135 @@ +using Microsoft.EntityFrameworkCore; +using Volo.Abp.EntityFrameworkCore; + +namespace Volo.Abp.Identity.EntityFrameworkCore +{ + /// + /// Base class for the Entity Framework database context used for identity. + /// + public class IdentityDbContext : AbpDbContext + { + /// + /// Initializes a new instance of . + /// + /// The options to be used by a . + public IdentityDbContext(DbContextOptions options) + : base(options) + { } + + /// + /// Gets or sets the of Users. + /// + public DbSet Users { get; set; } + + /// + /// Gets or sets the of User claims. + /// + public DbSet UserClaims { get; set; } + + /// + /// Gets or sets the of User logins. + /// + public DbSet UserLogins { get; set; } + + /// + /// Gets or sets the of User roles. + /// + public DbSet UserRoles { get; set; } + + /// + /// Gets or sets the of User tokens. + /// + public DbSet UserTokens { get; set; } + + /// + /// Gets or sets the of roles. + /// + public DbSet Roles { get; set; } + + /// + /// Gets or sets the of role claims. + /// + public DbSet RoleClaims { get; set; } + + /// + /// Configures the schema needed for the identity framework. + /// + /// + /// The builder being used to construct the model for this context. + /// + protected override void OnModelCreating(ModelBuilder builder) + { + builder.Entity(b => + { + b.ToTable("IdentityUsers"); + + b.Property(u => u.ConcurrencyStamp).IsConcurrencyToken(); + b.Property(u => u.UserName).HasMaxLength(256); + b.Property(u => u.NormalizedUserName).HasMaxLength(256); + b.Property(u => u.Email).HasMaxLength(256); + b.Property(u => u.NormalizedEmail).HasMaxLength(256); + + b.HasMany(u => u.Claims).WithOne().HasForeignKey(uc => uc.UserId).IsRequired(); + b.HasMany(u => u.Logins).WithOne().HasForeignKey(ul => ul.UserId).IsRequired(); + b.HasMany(u => u.Roles).WithOne().HasForeignKey(ur => ur.UserId).IsRequired(); + + b.HasIndex(u => u.NormalizedUserName).HasName("UserNameIndex").IsUnique(); + b.HasIndex(u => u.NormalizedEmail).HasName("EmailIndex"); + }); + + builder.Entity(b => + { + b.ToTable("IdentityRoles"); + + b.Property(r => r.ConcurrencyStamp).IsConcurrencyToken(); + b.Property(u => u.Name).HasMaxLength(256); + b.Property(u => u.NormalizedName).HasMaxLength(256); + + //TODO: Relation & Foreign Key! + //b.HasMany(r => r.Users).WithOne().HasForeignKey(ur => ur.RoleId).IsRequired(); + b.HasMany(r => r.Claims).WithOne().HasForeignKey(rc => rc.RoleId).IsRequired(); + + b.HasIndex(r => r.NormalizedName).HasName("RoleNameIndex").IsUnique(); + }); + + builder.Entity(b => + { + b.ToTable("IdentityUserClaims"); + + //TODO: Index? + //TODO: Foreign Keys? + }); + + builder.Entity(b => + { + b.ToTable("IdentityRoleClaims"); + + //TODO: Index? + //TODO: Foreign Keys? + }); + + builder.Entity(b => + { + b.ToTable("IdentityUserRoles"); + + b.HasIndex(r => new { r.UserId, r.RoleId }).IsUnique(); + }); + + builder.Entity(b => + { + b.ToTable("IdentityUserLogins"); + + b.HasIndex(l => new { l.UserId, l.LoginProvider, l.ProviderKey }).IsUnique(); + //TODO: Foreign Keys? + }); + + builder.Entity(b => + { + b.ToTable("IdentityUserTokens"); + + b.HasIndex(l => new {l.UserId, l.LoginProvider, l.Name}).IsUnique(); + //TODO: Foreign Keys? + }); + } + } +} \ No newline at end of file diff --git a/src/Volo.Abp.Identity.EntityFrameworkCore/project.json b/src/Volo.Abp.Identity.EntityFrameworkCore/project.json new file mode 100644 index 0000000000..f36718bb3a --- /dev/null +++ b/src/Volo.Abp.Identity.EntityFrameworkCore/project.json @@ -0,0 +1,16 @@ +{ + "version": "1.0.0-*", + + "dependencies": { + "NETStandard.Library": "1.6.1", + "Volo.Abp.EntityFrameworkCore": "1.0.0-*", + "Microsoft.EntityFrameworkCore.Relational": "1.1.0", + "Volo.Abp.Identity": "1.0.0-*" + }, + + "frameworks": { + "netstandard1.6": { + "imports": "dnxcore50" + } + } +}