Dynamic Scaffolding? RRS feed

  • Question

  • User925837561 posted

    I've been reading the walkthoughs and watched various videos on how to get started with Dynamic Data Controls, and am pretty amazed at how quickly you can get a reasonably well featured UI together.  However everything I've seen so far assumes that you will use a designer build a LINQ to SQL (or use a predefined class structure).  Can I programmatically build these models on the fly?  I think I'm asking if I can use code to generate a dbml file for example.  Is this possible?  If so can anyone point me in the direction of some further reading.

    Many thanks in advance, and apologies if I've asked a dumb question.

    Tuesday, October 17, 2017 7:56 PM

All replies

  • User-335504541 posted

    Hi Alan Moseley,

    I think I'm asking if I can use code to generate a dbml file for example.  Is this possible?

    I'm afraid it is not possible, you have to use vs to create the dbml file.

    If you wants to use code to create the model, I think you could try to use EF code-first.

    Here is the reference:




    Best Regards,


    Wednesday, October 18, 2017 9:15 AM
  • User925837561 posted

    As I understand it, and please correct me if this is not the case, I would still have to manually create the structure of my classes in a code file.  And this would mean that when the database changes I would have to manually update my code and recompile.  This is what I am trying to avoid.  I want entries in a "schema" database to be able to control the structure of the tables in a "data" database and dynamically generate all of this.  Currently my solution is to generate my form using code, then another set of code to handle the two way databinding.  It all works, but I was just hoping that dynamic data controls would render my code useless.

    Thanks for taking the time to respond Billy.  Regards


    Wednesday, October 18, 2017 10:58 AM
  • User-330204900 posted

    you certainly could build the Models on the fly with Linq to SQL (using SQLMETAL.exe but probably not with EF, and you can manually reload the metadata for each table at runtime with:


    But you will have to do some work to get the MetaModel to get the initial tables.

    Note I am talking about Asp.Net Web Forms Dynamic Data which does not use Scaffolding it uses Templates.

    Wednesday, October 18, 2017 1:05 PM
  • User925837561 posted

    That's very interesting, thanks.  The output options for SQLMETAL include 'map' which writes an XML file.  Do you know if Dynamic Data can use this XML file instead of a dbml?

    I am using asp.net web forms as you suggest.  What trust level would be required by my application for a user to be able to trigger SQLMETAL?


    Wednesday, October 18, 2017 1:41 PM
  • User-330204900 posted

    No Dynamic Data only uses the DBML file which generates the data context code and entities, note when using SQL Metal you will need to force a compile of the site unless you are using a website instead of a project. (note web forms websites are compiled at runtime by asp.net) and edit of web.config will force a recompile of a website.

    Wednesday, October 18, 2017 2:15 PM
  • User925837561 posted

    Does the link below help the solution I am looking for?  Whilst it's not specifically discussing Dynamic Data, it is suggesting that you can load an XML file (which of course I could generate myself without SQLMETAL if I made the effort) into a datacontext.  If this is indeed possible, do you think this "dynamic" datacontext could be linked to a dynamic data website?



    Wednesday, October 18, 2017 3:23 PM
  • User-330204900 posted

    Dynamic Data only Supports Linq to SQL context and Entity Framework Data Context. You can use Dynamic Data with ObjectDataSource but it's a lot of work that the Asp.Net team abandoned.

    Probably the best question I can give you is what are you trying to achieve, is it a CMS? I am not asking how you want to achieve it but what is the end result and then I can better advise you as to whether DD will be any use to you.

    Thursday, October 19, 2017 10:01 AM
  • User925837561 posted

    My web application is kind of like Zoho if you've heard of it.  It allows users to define what data they want to store, and define basic entry screens for updating this data.  A bit like creating your own MS Access database with forms and reports, but in a browser.  Currently the data entry screen layout is handled through extensive use of dynamically added custom controls which perform the databindings.  It all works fine.  I was just wondering though whether in a future version of my application I could replace some of this complexity with Dynamic Data.  I had a play with SQLMETAL, creating XML maps, and loading these into DataContexts yesterday and am coming to the conclusion that the data structures need to be rigid for it to all work.  I could therefore make it work by creating a bunch of columns in tables which are redundant until a user configures them for use, but this just sounds messy and inefficient.

    Thanks so much for your comments, you have given me plenty to go on.  And whilst it doesn't seem like I can make use of this technology right now, it might be of use in other projects in the future, and now I am more aware of what it can do.  Kind regards.

    Thursday, October 19, 2017 11:15 AM
  • User-330204900 posted

    You are right DD look for a rigid data structure and was never intended to work with dynamically created databases. I think it's LOT of work to get there and there is no future development with it being a part of web forms. all the teams resources are in asp.net core now. you could leverage some of DD features if you put the work in such as field templates to handle validation and formatting etc. but you would need to spend a lot of time with DD to get upto speed with it first and it may never fully do what you want. sorry

    Thursday, October 19, 2017 12:42 PM
  • User925837561 posted

    No apologies needed, you have been most helpful.

    Thursday, October 19, 2017 3:26 PM