// Copyright (c) Microsoft Open Technologies, Inc. // All Rights Reserved // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR // CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING // WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF // TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR // NON-INFRINGEMENT. // See the Apache 2 License for the specific language governing // permissions and limitations under the License. using System; using Microsoft.Data.Entity; using Microsoft.Data.Entity.SqlServer; using Microsoft.Data.Entity.InMemory; using Microsoft.Data.Entity.Metadata; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection.Fallback; namespace Microsoft.AspNet.Identity.Entity { public class IdentityContext : IdentityContext { public IdentityContext() { } public IdentityContext(IServiceProvider serviceProvider) : base(serviceProvider) { } } public class IdentityContext : DbContext where TUser : EntityUser where TRole : EntityRole where TUserLogin : IdentityUserLogin where TUserRole : IdentityUserRole where TUserClaim : IdentityUserClaim where TKey : IEquatable { public DbSet Users { get; set; } public DbSet Roles { get; set; } public IdentityContext(IServiceProvider serviceProvider) : base(serviceProvider) { } public IdentityContext() { } protected override void OnConfiguring(DbContextOptions builder) { //#if NET45 // builder.UseSqlServer(@"Server=(localdb)\v11.0;Database=IdentityDb3;Trusted_Connection=True;"); //#else builder.UseInMemoryStore(); //#endif } protected override void OnModelCreating(ModelBuilder builder) { builder.Entity() .Key(u => u.Id) .Properties(ps => ps.Property(u => u.UserName)); //.ToTable("AspNetUsers"); builder.Entity() .Key(r => r.Id); //.ToTable("AspNetRoles"); builder.Entity() .Key(u => u.Id) //TODO: .Key(r => new { r.UserId, r.RoleId }) .ForeignKeys(fk => fk.ForeignKey(f => f.UserId)) .ForeignKeys(fk => fk.ForeignKey(f => f.RoleId)); //.ToTable("AspNetUserRoles"); builder.Entity() .Key(u => u.Id) //TODO: .Key(l => new { l.LoginProvider, l.ProviderKey, l.UserId }) .ForeignKeys(fk => fk.ForeignKey(f => f.UserId)); //.ToTable("AspNetUserLogins"); builder.Entity() .Key(c => c.Id) .ForeignKeys(fk => fk.ForeignKey(f => f.UserId)); //.ToTable("AspNetUserClaims"); } } }