none
Entity Framework code first adding models from other projects RRS feed

  • Question

  • Normally one would write its model classes and create a DbContext with several DbSet's to the corresponding modelclasses to create the database in EF code first.

    The Prism library allows you to create modules. Modules live in the same solution but as another Project inside the solution, or maybe it could be a DLL from another solution.

    My question now: what if you have for example a prism module (a separated project) with its own models (and DbSet definitions). How can you add or inject (or let EF discover) these model classes and DbSet's from that module and add them to the existing EF database)?

    Lets say some external person writes a plugin (a prism module) with its own database models and offcourse the corresponding DbSet definitions. If that person drops that prism module DLL in the program directory, how would the core application (at startup normally) know that there are other DbSet's from the prism module that also need to be created in the database if they don't exist yet. (And how can they be added?)

    Thanks in advance.

    Could somebody give a code sample of how to do this? I was thinking about the MEF attributes [ImportMany] and [ExportMany] but i'm not sure if that could work.

     

    (fyi, I've asked this question also on SO)

    Thursday, December 22, 2011 10:43 PM

All replies

  • *bump*
    Sunday, December 25, 2011 8:55 PM
  • Hi juFo,

    Welcome!
    We will do some more pending research  about your problem and come back as soon as possible, Thanks for understanding.
    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, December 26, 2011 12:23 PM
    Moderator
  • I would love to hear a solution. :)
    Thursday, December 29, 2011 8:34 AM
  • Hi,

    I came across the following on CodePlex. Let me know if this example is helpful:

    Batch Scheduler using  .NET 4, MEF and Entity Framework 4.1 (Magic Unicorn)
    http://batchscheduler.codeplex.com/

    Thanks,

    Cathy Miller

    Microsoft Online Community Support

    Thursday, December 29, 2011 7:23 PM
    Moderator
  • Cathy, thanks already but as far as I can see they only have their DbSets (db tables) defined in one place:

            public DbSet<pcAuditLog> Audits { get; set; }             
            public DbSet<pcJobAction> JobActions { get; set; }
            public DbSet<pcPlugInValue> PlugIns { get; set; }
    

    How would you add a DbSet<SomethingElse> which is defined in another project to that MainContext (DbContext) ?
    That is more something I 'm looking for..

    Monday, January 2, 2012 9:57 PM