Reputation: 952
I need to merge my ApplicationDbContext with my DemoPoolEntities context. What do I need to do to to properly merge the two? The reason I need to do this is so that I can access the ApplicationUser
data from the Customer
class which is a part of the DemoPoolEntities
context. I am not sure where to start to merge these two so they are both in one DbContext
.
ApplicationDbContext
using System.Data.Entity;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
namespace DemoPool.Models
{
// You can add profile data for the user by adding more properties to your ApplicationUser class, please visit https://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
public class ApplicationUser : IdentityUser
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DemoPoolEntities", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
}
DemoPoolEntities
namespace DemoPool.Models
{
using System;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using Microsoft.AspNet.Identity.EntityFramework;
public partial class DemoPoolEntities : DbContext
{
public DemoPoolEntities()
: base("name=DemoPoolEntities")
{
}
public virtual DbSet<Condition> Conditions { get; set; }
public virtual DbSet<Customer> Customers { get; set; }
public virtual DbSet<Kit> Kits { get; set; }
public virtual DbSet<Loan> Loans { get; set; }
public virtual DbSet<Product> Products { get; set; }
public virtual DbSet<Type> Types { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Condition>()
.Property(e => e.Condition1)
.IsUnicode(false);
modelBuilder.Entity<Customer>()
.Property(e => e.CompanyName)
.IsUnicode(false);
modelBuilder.Entity<Customer>()
.Property(e => e.FirstName)
.IsUnicode(false);
modelBuilder.Entity<Customer>()
.Property(e => e.LastName)
.IsUnicode(false);
modelBuilder.Entity<Customer>()
.Property(e => e.PhoneNumber)
.IsUnicode(false);
modelBuilder.Entity<Customer>()
.Property(e => e.Email)
.IsUnicode(false);
modelBuilder.Entity<Customer>()
.Property(e => e.Address1)
.IsUnicode(false);
modelBuilder.Entity<Customer>()
.Property(e => e.Address2)
.IsUnicode(false);
modelBuilder.Entity<Customer>()
.Property(e => e.City)
.IsUnicode(false);
modelBuilder.Entity<Customer>()
.Property(e => e.State)
.IsUnicode(false);
modelBuilder.Entity<Customer>()
.Property(e => e.Zip)
.IsUnicode(false);
modelBuilder.Entity<Kit>()
.Property(e => e.KitName)
.IsUnicode(false);
modelBuilder.Entity<Loan>()
.Property(e => e.TrackingNumber)
.IsUnicode(false);
modelBuilder.Entity<Product>()
.Property(e => e.ProductName)
.IsUnicode(false);
modelBuilder.Entity<Product>()
.Property(e => e.Description)
.IsUnicode(false);
modelBuilder.Entity<Product>()
.Property(e => e.ProductNumber)
.IsUnicode(false);
modelBuilder.Entity<Product>()
.Property(e => e.SerialNumber)
.IsUnicode(false);
modelBuilder.Entity<Product>()
.Property(e => e.Manufacturer)
.IsUnicode(false);
modelBuilder.Entity<Type>()
.Property(e => e.Type1)
.IsUnicode(false);
modelBuilder.Entity<IdentityUserLogin>()
.HasKey<string>(l => l.UserId);
modelBuilder.Entity<IdentityRole>()
.HasKey<string>(r => r.Id);
modelBuilder.Entity<IdentityUserRole>().HasKey(r => new { r.RoleId, r.UserId });
}
}
}
Upvotes: 1
Views: 121
Reputation: 4125
DemoPoolEntities
need to inherit from ApplicationDbContext
public partial class DemoPoolEntities : ApplicationDbContext
{
...
}
Upvotes: 1