locked
Dynamically handling change in the database RRS feed

  • Question

  • Hi,

    I have a database with a table whose structure can be modified from time to time. I mean that columns can be added or deleted. So as I would like not to recompile my server app (!), I imagine that I can read the new edmx file (I suppose that after the table structure change, I start the edmgen tool to regenerate the edmx), and then use the IL generator to build a POCO class which will match the new table structure.

    Now the problem is on my client part, which is a Silverlight 4.0 client. This part references my WCF Data Service, which have changed. And I can't see how I can avoid the compilation.

    Thanks for your comments !


    Philippe
    Wednesday, September 1, 2010 4:44 PM

Answers

  • I answer to my question. Yes it is possible to recompile using a simple MsBuild command.

    But the references.cs file is NOT regenerated in the silverlight project. And it appears that I can't automate that, and that I need to click on the "Update service reference" menu on Visual Studio, which is precisely what I want to avoid.

    Best regards


    Philippe
    • Marked as answer by PhilTheGap Thursday, September 2, 2010 3:14 PM
    Thursday, September 2, 2010 10:33 AM

All replies

  • Hi,

    The interesting question is, how would you imagine it working even if you somehow could avoid the recompilation. The client application will access properties on the entity classes to get to the data. Now if you change or remove a property the existing code will break, so you will have to go and fix it. If you add new properties the client code would not see those either, so it would not be able to use them. So aside from just a very generic data grid type of user interface, how would you make your client app work with the new shape of the data without recompiling it?

    To answer your question, you have to recompile the client to pick up the new entity classes. You could in theory just parse the responses as XML in which case no classes are necessary, but then you loose all the functionality provided by the client library.

    Thanks,


    Vitek Karas [MSFT]
    Thursday, September 2, 2010 12:13 AM
    Moderator
  • Thanks for your answer, Vitek.

    To answer your last question, the answer is : binding a DataForm with a class generated at runtime, which is possible (http://forums.silverlight.net/forums/t/187306.aspx).

    Now I can recompile after a change in the database, but I would like this recompilation to be automatic, I mean not made by hand. 

    So, I think that the compilation regenerates the references.cs class in the client project. As far as you know (I know this is not the right NG), is it possible to compile a Visual Studio 2010 solution (sln file) without Visual Studio, just with a "licence free" compiler ?

    Best regards


    Philippe
    Thursday, September 2, 2010 7:11 AM
  • I answer to my question. Yes it is possible to recompile using a simple MsBuild command.

    But the references.cs file is NOT regenerated in the silverlight project. And it appears that I can't automate that, and that I need to click on the "Update service reference" menu on Visual Studio, which is precisely what I want to avoid.

    Best regards


    Philippe
    • Marked as answer by PhilTheGap Thursday, September 2, 2010 3:14 PM
    Thursday, September 2, 2010 10:33 AM
  • Hi,

    Simple build of the project will not regenerate the reference (by design as you probably don't want to redownload the service document on each build, would take long and would require network for build).

    There's a command line utility, which you can use to generate the file outside of VS - datasvcutil.exe http://msdn.microsoft.com/en-us/library/ee383989.aspx

    You should be able to write a simple msbuild target which will execute this utility to regenerate the code for you. And thus make it part of the build.

    Thanks,


    Vitek Karas [MSFT]
    Thursday, September 2, 2010 4:09 PM
    Moderator
  • Thanks Vitek.

    I've tried the datasvcutil command with the server edmx file as input. It produces an empty reference.cs file... Perhaps I should run it with the URL argument ?

    Also, I need to generate the edmx file on the client. How can I do that ?

    Regards


    Philippe
    Friday, September 3, 2010 7:09 AM