none
How to Reference Another Model Entity in EF model Designer RRS feed

  • Question

  • hi.

    I am working with EF 4.0 now, but there are some issue about reference each Model entity between Models.

    for example ,if i have hundreds of Entitys mapping to my database table.

    is there any way to split these so many entity to some seperate Model files and don't need to redefine those referenced entity that useing by other entity like inheritance ,reference .

    like this scenario below

    there has a entity named Document mapping to TDocument Database Table

    in the first EF models File, i will create a new entity named SaleOrder that inherit from Document Entity 

    but ,when i want to create another new entity ,for example, named PurchaseOrder that also inherit from Document Entity in another EF Models File (Second Models FIle) for seperating models designing porpuse, i must drag the Mapping Database Table TDoument to Second Models Designer,

    the one Document Entity Model Recreate again!

    is there any idea or good pattern or practise to using EF that have so much Entities ?

    the next version of EF can has this ability?

    thanks.

    Matt Lin

     


    DON'T TRY SO HARD,THE BEST THINGS COME WHEN YOU LEAST EXPECT THEM TO.

    Thursday, April 12, 2012 7:46 AM

Answers

  • Hi Matthew LIN,

    Yes, you can split entities into multiple EDMX files, but in this way, you have to take care of synchronous. Furthermore, please make sure entities have relationship need to be in the same EDMX file, otherwise, you will lose the navigation properties.

    Best Regards


    Fighting like Allen Iverson. Neve give up!

    Tuesday, April 17, 2012 7:08 AM

All replies

  • Hi Matthew LIN,

    Welcome to MSDN Forum.

    Using Entity Framework with too many entities, smaller EDMX files is a good choice. But creating inheritance need to be done in one edmx file, otherwise, as you said, you have to add the base table to another edmx file, then the compiler will throw lots of errors. I think you may want to improve the performance, so you want to split entities into multiple EDMX files. There are many ways can help you to improve the performance with too many entities, such as using pre-generated view and compiled queries. Here's an article introduces good practices to improve the performance of entity framework, I think it can help you, please refer to it. Furthermore, in EF5.0, the performance is greatly improved, here's an article introduces the performance improving in EF5.0, if you are interested in it, please refer here.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Monday, April 16, 2012 3:53 AM
    Moderator
  • hi.

    thank you very much.

    i know pre-generated view and compiled queries is a good idea for performance.

    maybe ,the hundreds of entities diagram graph in single desginer makes me crazy.

    ....


    DON'T TRY SO HARD,THE BEST THINGS COME WHEN YOU LEAST EXPECT THEM TO.

    Tuesday, April 17, 2012 7:05 AM
  • Hi Matthew LIN,

    Yes, you can split entities into multiple EDMX files, but in this way, you have to take care of synchronous. Furthermore, please make sure entities have relationship need to be in the same EDMX file, otherwise, you will lose the navigation properties.

    Best Regards


    Fighting like Allen Iverson. Neve give up!

    Tuesday, April 17, 2012 7:08 AM