locked
Expose EDMX with no code behind? RRS feed

  • Question

  • Hi,

    Is it possible to built only the EDMX file with all XML, without the code behind and have Entity Framework to understand this? I wish to publish EDMX through WCF - but in a dynamic form, where I can change the metadata (scheme) without code re-compiling.

    Any ideas?

    Wednesday, September 22, 2010 7:55 AM

Answers

  • Hi,

    Yes, you can clear out the custom tool property of the .edmx file and change the Build Action property from Entity Deploy to Content and change the Copy to Output Directory to Copy Always. On the other end of the service connection you can probably (I never tried this, for obvious reasons) dynamically create an assembly that embeds the CSDL, SSDL and MSL.

    But (and this is a big BUT), I dont see the point in trying something like this, because you still won't be able to interact with a database and you'll encounter countless problems with dynamic proxies. It will give you a big headache trying to accomplish this and I don't think it will work properly.

    So, if you just want to publish your .edmx xml files for the purpose of providing information, it can be done. If you really want to use the model on the other side of the service connection I wouldn't even try it.


    With regards,

    Patriek
    If this reply is of help to you, please don't forget to mark it as an answer.
    Wednesday, September 22, 2010 8:26 AM
  • I'm not sure I completely understand what you're trying to accomplish but it sounds like your attempting to write your own edmx editor of sorts that applies mapping changes on the fly; is that correct?

    This can be done without recompiling as long as the Metadata Artifiact Processing directive is set to "Copy to Output Directory" instead of "Embed in Assembly. However, you're not going to be able to expose the metadata entities defined by EF directly over the wire as they are not serializable. The best you could probably do is treat the EDMX files as doc literals and rehydrate the metadata model manually on the other side, make your changes, and send the edits back as a doc literal and overwrite the old files...

     If you change the generation strategy to none none of the "code behind" files will be generated

    ?

    Wednesday, September 22, 2010 10:49 PM

All replies

  • Hi,

    Yes, you can clear out the custom tool property of the .edmx file and change the Build Action property from Entity Deploy to Content and change the Copy to Output Directory to Copy Always. On the other end of the service connection you can probably (I never tried this, for obvious reasons) dynamically create an assembly that embeds the CSDL, SSDL and MSL.

    But (and this is a big BUT), I dont see the point in trying something like this, because you still won't be able to interact with a database and you'll encounter countless problems with dynamic proxies. It will give you a big headache trying to accomplish this and I don't think it will work properly.

    So, if you just want to publish your .edmx xml files for the purpose of providing information, it can be done. If you really want to use the model on the other side of the service connection I wouldn't even try it.


    With regards,

    Patriek
    If this reply is of help to you, please don't forget to mark it as an answer.
    Wednesday, September 22, 2010 8:26 AM
  • Hi Patriek,

    Thank you for the reply. I see your point on the design - but I can assure you there is a great reason for it :) We are building based on dynamic designs, where there are many integrations (through WCF) and a lot of changes to the DB (changes done through a tool we wrote). We need to publish the changes a strongly-typed classes preferrable over LINQ through WCF as an API.

    Do you see an option to build one generic class on the server side handling all requests? A map-to class for all entities in the EF framework. I implemented a design like this through WCF and custom WSDL and and KnowTypeFormatter where we capture all attributes into a DynamicClass with array of attributes and values.

    Do you think it could be possible - with EF - to create such a dynamic class?

     

    Wednesday, September 22, 2010 8:45 AM
  • I'm not sure I completely understand what you're trying to accomplish but it sounds like your attempting to write your own edmx editor of sorts that applies mapping changes on the fly; is that correct?

    This can be done without recompiling as long as the Metadata Artifiact Processing directive is set to "Copy to Output Directory" instead of "Embed in Assembly. However, you're not going to be able to expose the metadata entities defined by EF directly over the wire as they are not serializable. The best you could probably do is treat the EDMX files as doc literals and rehydrate the metadata model manually on the other side, make your changes, and send the edits back as a doc literal and overwrite the old files...

     If you change the generation strategy to none none of the "code behind" files will be generated

    ?

    Wednesday, September 22, 2010 10:49 PM
  • Hi,

     

    I am writing to check the status of the issue on your side.  Would you mind letting us know the result of the suggestions? 

     

    If you need further assistance, please feel free to let me know.   I will be more than happy to be of assistance.

     

    Have a nice day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, September 27, 2010 3:07 AM