0

i have two completely difference project site like :

adminPanel(asp mvc site),utilities(classLibrary),mobileConnection(asp web api)

adminPanel Project and MobileConnection Project has separably authentication but their account has some share field,

Utilities Code (share with two project) :

public class MobileApplicationUser : IdentityUser
{
    public virtual Profile Profile { get; set; }

    public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<MobileApplicationUser> manager, string authenticationType)
    {       
        var userIdentity = await manager.CreateIdentityAsync(this, authenticationType);
        return userIdentity;
    }
}

public class AdminApplicationUser : IdentityUser
{
    public virtual Organization organization { get; set; }

    public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<AdminApplicationUser> manager, string authenticationType)
    {         
        var userIdentity = await manager.CreateIdentityAsync(this, authenticationType);
        return userIdentity;
    }

}

admin Project Code :

public class ApplicationDbContext : IdentityDbContext<AdminApplicationUser>
{
    public ApplicationDbContext() : base("DefaultConnection", throwIfV1Schema: false)
    {

    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);

        modelBuilder.Entity<AdminApplicationUser>().ToTable("AdminUser");
        modelBuilder.Entity<IdentityRole>().ToTable("AdminRole");
        modelBuilder.Entity<IdentityUserRole>().ToTable("AdminUserRole");
        modelBuilder.Entity<IdentityUserClaim>().ToTable("AdminUserClaim");
        modelBuilder.Entity<IdentityUserLogin>().ToTable("AdminUserLogin");
    }

    public static ApplicationDbContext Create()
    {
        return new ApplicationDbContext();
    }

    public DbSet<Profile> Profiles { get; set; }
    public DbSet<Competition> Competitions { get; set; }
    public DbSet<Message> Messages { get; set; }
    public DbSet<Organization> Organizations { get; set; }

}

mobileConnection Project Code :

 public class ApplicationDbContext : IdentityDbContext<MobileApplicationUser>
 {
    public ApplicationDbContext() : base("DefaultConnection", throwIfV1Schema: false)
    {
    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);

        modelBuilder.Entity<AdminApplicationUser>().ToTable("MobileUser");
        modelBuilder.Entity<IdentityRole>().ToTable("MobileRole");
        modelBuilder.Entity<IdentityUserRole>().ToTable("MobileUserRole");
        modelBuilder.Entity<IdentityUserClaim>().ToTable("MobileUserClaim");
        modelBuilder.Entity<IdentityUserLogin>().ToTable("MobileUserLogin");
    }

    public static ApplicationDbContext Create()
    {
        return new ApplicationDbContext();
    }

    public DbSet<Profile> Profiles { get; set; }
    public DbSet<Competition> Competitions { get; set; }
    public DbSet<Message> Messages { get; set; }
    public DbSet<Organization> Organizations { get; set; }

}

my profile and organization has relation together, so... i can`t update database both project and have my goal! what can i do ?

4
  • i don`t want to have one DbContext and do separate my authorization with Role and users Commented Jan 13, 2016 at 23:05
  • Your goal is unclear. What is the end state? Commented Jan 13, 2016 at 23:19
  • i want one share database with two ASP MVC Web application(they have separate authentication) Commented Jan 13, 2016 at 23:29
  • What does the code that you have shown have to do with that goal? Commented Jan 13, 2016 at 23:30

1 Answer 1

1

Assume this is a code first question. Yes you can have 1 DB Context accessing multiple Databases or have several DBContexts access 1 database. Managing the migration is the key challenge.

Bounded DBContext and Entity framework

is a good place to start your research

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.