none
Can you have an Entity Framework project that can model two databases where one is a sub set of the other? RRS feed

  • Question

  • Hi all;

    Here is what I am trying to accomplish. I currently have an EF project (model first) that will contain all the data for my application, across all users. I would like to have a db with a subset of this db (user specific) but I would like it to derive from the same model or even be in the same model project, so I don't have to duplicate code. is that possible?


    Shawn

    Thursday, July 16, 2015 7:26 PM

Answers

  • You can place each EF model into separate namespaces in single project -- namespace separation. You can do that in VS by creating a Folder in the project and pointing EF to the folder to create the model. You can call the folders Model1 and Model2 or whatever you want to name them. 

    but I would like it to derive from the same model

    That statement of yours above is questionable, and I don't know what you are talking about.

     
    Thursday, July 16, 2015 7:55 PM
  • if db a is a superset of db b, then you can probably just use the model b on db a, just use the DBContext constructor that takes a connection string


    Visual C++ MVP

    • Marked as answer by seckley Saturday, July 25, 2015 10:07 AM
    Thursday, July 16, 2015 8:04 PM

All replies

  • You can place each EF model into separate namespaces in single project -- namespace separation. You can do that in VS by creating a Folder in the project and pointing EF to the folder to create the model. You can call the folders Model1 and Model2 or whatever you want to name them. 

    but I would like it to derive from the same model

    That statement of yours above is questionable, and I don't know what you are talking about.

     
    Thursday, July 16, 2015 7:55 PM
  • if db a is a superset of db b, then you can probably just use the model b on db a, just use the DBContext constructor that takes a connection string


    Visual C++ MVP

    • Marked as answer by seckley Saturday, July 25, 2015 10:07 AM
    Thursday, July 16, 2015 8:04 PM
  • Thanks Jiang;

    I think that's exactly what I was looking for.

    DA924 was right I didn't say it correctly. I really should have given a better example. So I have a model that my main DB uses, this is for the global application. It has tables like:

    user, AccountInfo, Products, transactions,...

    in the second db, which is to be local to the user(Desktop app, or mobile app). This db would contain all the tables that are specific to what would be relevant to the user.


    Shawn

    Thursday, July 16, 2015 9:33 PM