0

I've been tasked with creating a sub application of an existing site. The sub application needs to make use of the users in the parent site but this is under a different database.

I'm using Entity Framework code first for the new site. However, I wish to create a mapping between the parent database user table and the new code first database.

Is this possible?

  • ParantDB.dbo.User
  • SubDB.dbo.Order
  • SubDB.dbo.OrderItems

    public class Order
    {
       public int OrderId { get; set; }
       public User Customer { get; set; } // Maintains a relationship user table  
    }
    
    public class User
    {
       public int UserId { get; set; }
       ....
    }
    

    public class SubSiteContext : DbContext {

         public DbSet<Order> Orders { get; set; }
         public DbSet<User> Users { get; set; }
    
         protected override void OnModelCreating(DbModelBuilder modelBuilder)
         {
              //???? I Presume I need to do the mapping here??
         }
    }
    

1 Answer 1

1

Context can be bound only to a single connection string = single database. The workaround for this cab be for example creating database view in your SubDB which will internally hide query to ParentDB.dbo.Users and map this view in the same way as you map tables.

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.