Created initial IdentityDbContext

pull/81/head
Halil İbrahim Kalkan 9 years ago
parent 60000cebf0
commit 4c53e6ab67

@ -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

@ -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")]

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>439dfc0f-1ba2-464f-900e-ea7e18c08975</ProjectGuid>
<RootNamespace>
</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

@ -0,0 +1,135 @@
using Microsoft.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
namespace Volo.Abp.Identity.EntityFrameworkCore
{
/// <summary>
/// Base class for the Entity Framework database context used for identity.
/// </summary>
public class IdentityDbContext : AbpDbContext<IdentityDbContext>
{
/// <summary>
/// Initializes a new instance of <see cref="IdentityDbContext"/>.
/// </summary>
/// <param name="options">The options to be used by a <see cref="DbContext"/>.</param>
public IdentityDbContext(DbContextOptions<IdentityDbContext> options)
: base(options)
{ }
/// <summary>
/// Gets or sets the <see cref="DbSet{TEntity}"/> of Users.
/// </summary>
public DbSet<IdentityUser> Users { get; set; }
/// <summary>
/// Gets or sets the <see cref="DbSet{TEntity}"/> of User claims.
/// </summary>
public DbSet<IdentityUserClaim> UserClaims { get; set; }
/// <summary>
/// Gets or sets the <see cref="DbSet{TEntity}"/> of User logins.
/// </summary>
public DbSet<IdentityUserLogin> UserLogins { get; set; }
/// <summary>
/// Gets or sets the <see cref="DbSet{TEntity}"/> of User roles.
/// </summary>
public DbSet<IdentityUserRole> UserRoles { get; set; }
/// <summary>
/// Gets or sets the <see cref="DbSet{TEntity}"/> of User tokens.
/// </summary>
public DbSet<IdentityUserToken> UserTokens { get; set; }
/// <summary>
/// Gets or sets the <see cref="DbSet{TEntity}"/> of roles.
/// </summary>
public DbSet<IdentityRole> Roles { get; set; }
/// <summary>
/// Gets or sets the <see cref="DbSet{TEntity}"/> of role claims.
/// </summary>
public DbSet<IdentityRoleClaim> RoleClaims { get; set; }
/// <summary>
/// Configures the schema needed for the identity framework.
/// </summary>
/// <param name="builder">
/// The builder being used to construct the model for this context.
/// </param>
protected override void OnModelCreating(ModelBuilder builder)
{
builder.Entity<IdentityUser>(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<IdentityRole>(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<IdentityUserClaim>(b =>
{
b.ToTable("IdentityUserClaims");
//TODO: Index?
//TODO: Foreign Keys?
});
builder.Entity<IdentityRoleClaim>(b =>
{
b.ToTable("IdentityRoleClaims");
//TODO: Index?
//TODO: Foreign Keys?
});
builder.Entity<IdentityUserRole>(b =>
{
b.ToTable("IdentityUserRoles");
b.HasIndex(r => new { r.UserId, r.RoleId }).IsUnique();
});
builder.Entity<IdentityUserLogin>(b =>
{
b.ToTable("IdentityUserLogins");
b.HasIndex(l => new { l.UserId, l.LoginProvider, l.ProviderKey }).IsUnique();
//TODO: Foreign Keys?
});
builder.Entity<IdentityUserToken>(b =>
{
b.ToTable("IdentityUserTokens");
b.HasIndex(l => new {l.UserId, l.LoginProvider, l.Name}).IsUnique();
//TODO: Foreign Keys?
});
}
}
}

@ -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"
}
}
}
Loading…
Cancel
Save