none
How to mention some entity of an EDMX from another EDMX ? RRS feed

  • Question

  • I would like to :
     use EF 4.1, code first approach + EDMX and TT code generator
      define one first EDMX for generating pocos into one first assembly (base library)
      define another EDMX for generating pocos into a second assembly
      have the entities defined nto the second EDMX mention some entities of the first EDMX -- through inheritance or association
     
    Is it possible to some how reuse/import an EDMX into a second one ?
    Is it possible to do this across assemblies ?
     
    My ultimate goals are to :
        have sucessive layers of pocos (and related repositories...) by decreasing reusability.
        compare two sets of EDMX, each onerepresenting a version of a given database, in order to
        compute the delta of schemas (xml difference...) and
        (semi) automatically generate the code to migrate the content of the database.
     
    Any hint much appreciated. Thanks.
     
    Thierry

    Tuesday, June 21, 2011 11:45 AM

Answers

  • Thanks for your answer

    This link indirectly found through the one you provided seems the closest answer to my question.

    http://blogs.msdn.com/b/adonet/archive/2008/11/25/working-with-large-models-in-entity-framework-part-2.aspx

    Cheers

    Wednesday, June 29, 2011 3:57 PM

All replies

  • Hi Thierry,

    Welcome!

    Based on your description, we can code our class directly instead of generating POCOs by EDMX, you can refer here: http://blogs.msdn.com/b/adonet/archive/2011/04/11/ef-4-1-released.aspx and http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-code-first-walkthrough.aspx. According to your scenario, It means there are two DbContext or ObjectContext, I'm afriad there is a way to mention between different context, but you can use Detach entities from one context and Attach to the other one context.

    If I missunderstood, would you please feel free to let me know.

    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.

    Wednesday, June 22, 2011 7:07 AM
    Moderator
  • Hi Alan,

    Thanks for your reply.

    I am afraid I was not clear. I already use the approach you recommend : writing the pocos and the DbContext which will generate the database...

    But now our pocos are numerous and I would like to draw them and generate them as well as the DbContext... using an adapted version of the TT code generator here :

    http://blogs.msdn.com/b/adonet/archive/2010/01/25/walkthrough-poco-template-for-the-entity-framework.aspx
    

    But all my pocos are not in the same assembly. There is a Core assembly which contains some entity I would like to reuse / mention into some dependent assembly.

    In Core I'd like to have an EDMX(say Core.edmx) + TT generator and in say CoreDependent assembly I'd like to have another EDMX (say CoreDependent.edmx) which mentions some entity from  Core.edmx (THIS IS WHAT I DONT KNOW HOW TO ACHIEVE); it would use the same TT to generate the pocos and DbContext.

    I reckon a small solution with some code would be clearer.

    Thanks for your help

    Cheers

    Thierry

    Thursday, June 23, 2011 1:22 PM
  • Hi Alan,

    Thanks for your reply.

    I am afraid I was not clear. I already use the approach you recommend : writing the pocos and the DbContext which will generate the database...

    But now our pocos are numerous and I would like to draw them and generate them as well as the DbContext... using an adapted version of the TT code generator here :

    http://blogs.msdn.com/b/adonet/archive/2010/01/25/walkthrough-poco-template-for-the-entity-framework.aspx
    
    

    But all my pocos are not in the same assembly. There is a Core assembly which contains some entity I would like to reuse / mention into some dependent assembly.

    In Core I'd like to have an EDMX(say Core.edmx) + TT generator and in say CoreDependent assembly I'd like to have another EDMX (say CoreDependent.edmx) which mentions some entity from  Core.edmx (THIS IS WHAT I DONT KNOW HOW TO ACHIEVE); it would use the same TT to generate the pocos and DbContext.

    I reckon a small solution with some code would be clearer.

    Thanks for your help

    Cheers

    Thierry


    very interesting idea, but one edmx file is one ObjectContext and no inheritance among them. perhaps this link can help you how to load multiple edmx into one context but just for the same assembly. http://stackoverflow.com/questions/4975965/compose-queries-across-entity-data-models/4984198#4984198

    check this link may help you. http://stackoverflow.com/questions/5852223/inheritance-between-two-contexts-in-entity-framework

    Sunday, June 26, 2011 4:52 AM
  • Thanks for your answer

    This link indirectly found through the one you provided seems the closest answer to my question.

    http://blogs.msdn.com/b/adonet/archive/2008/11/25/working-with-large-models-in-entity-framework-part-2.aspx

    Cheers

    Wednesday, June 29, 2011 3:57 PM
  • Since obviously there is no support at the designer level, the best is to rely on code since I am using the .edmx with .tt code generator for producing Pocos.

    I adapted the Pocos generated so that they inherited some home-made PocoBase.

    I marked some entities as Ignore (Documentation.Long Summary).

    This way I can draw some entities on an .edmx coming from some reused .edmx whitout generating related code.

    Then I just need to add the missing navigation properties manually into some partial definition.

    I also generated the DbContexts and complemented them simarly.

    In Summary, I can

    - define a class library of Pocos using a first Edmx ; I generate the Pocos with a T4 generator; I have all Pocos inherit from a PocoBase type (optional depending on your needs); I also generate the DbContext from the Edmx

    - define a second Edmx which shows in the design some entities coming from the first Edmy; this is for documentation purpose only since no code related to this entity will be generated

    Pocos and DbContexts are generated into partial. The actual second DbContext inherits the first one.

    I just need to manually write  into some partial def, the navigation properties crossing the Edmx border (Pocos), the fluent configuration (DBContext)

    This is more consistent with a code first approach than tweaking the xml (csdl) underlying the Edmx file.

    Thursday, June 30, 2011 1:12 PM