Watch videos with subtitles in your language, upload your videos, create your own subtitles! Click here to learn more on "how to Dotsub"

Your First Scaffold and What is Dynamic Data?

0 (0 Likes / 0 Dislikes)
  • Embed Video

  • Embed normal player Copy to Clipboard
  • Embed a smaller player Copy to Clipboard
  • Advanced Embedding Options
  • Embed Video With Transcription

  • Embed with transcription beside video Copy to Clipboard
  • Embed with transcription below video Copy to Clipboard
  • Embed transcript

  • Embed transcript in:
    Copy to Clipboard
  • Invite a user to Dotsub
[♪ music ♪] [Microsoft] [] [ Dynamic Data] [What is Dynamic Data?] [How to Build a Scaffold Site] Hi this is Scott Hanselman, and this is the first in a series of how to screencasts on how to use Dynamic Data. In order to get your brain around what it is what is Dynamic Data and what has changed between the version of Visual Studio on the .net framework that you have and this new extended version. Let's just see it in action, and then we'll dig deeper and find out what makes this thing tick. So I'm going to start in Visual Studio by saying File, New Web Site. You will notice immediately that I've got some new project options. In this case, the Dynamic Data Website is new. We'll hit Okay, and we'll get a scaffolded default site. We open up the Solution Explorer and we can see immediately that there is a new folder there that we haven't seen before— the Dynamic Data Folder. And within that folder are other folders, full of information. Controls and pages—what does all that do? Well, let's back up for a minute and let's remember that this is about Dynamic Data so let's add a data context. See what this default Hello World site can do, and then we'll dig into the field templates and the page templates that are inside that folder. So I'm going to right click and say, "Add new item." I'd also like to LINQ to SQL class. And we'll use the, always necessary, Northwind database. It's letting me know I should put that in the App_Code folder so I will. We'll double click on the .dbml file, and we'll grab some things out of our database. We'll pull out Order Details, Orders, Products, Categories, maybe Suppliers. I could also use LINQ to entities. Tidy up a little bit. Close this. At this point we're generating some code so if I open this up, we'll see in the Northwind designer that we now have a Northwind Data Context. This was created by LINQ to SQL. You'd have a different one if you were using LINQ to entities. Let's let Dynamic Data know about this new data context. So we'll go into the global ASAX We notice in our application start that we've got a call to register routes. If you looked at you may be familiar with this notion of routing. This is actually also used in Dynamic Data. We've extended the routing system. So in that call to register routes we create a system.web.dynamicdata.metamodel. We have to let that model know about our database. I want to uncomment this 1 line here. And I'm going to change the YourDataContextType to NorthwindDataContext. And then at the end of the line there it says, "ScaffoldAllTables = false." Because I want to have all of my tables created in pages for each, I'm going to say, "ScaffoldAllTables = true." And let's go ahead and run it. So at this point all we've done is we've added a data context and we've registered it with the model and we hit F5. This is a pretty interesting Hello World. There's a lot going on here already. We've got our different tables. Look at the URL; see how it says /products/list? I've got a complete list of products. I'll hit Edit. I get an edit page. Again notice the URL. So the name of the table has appeared in that URL there. We'll back up, we'll look down at Suppliers. Notice that suppliers is related to products. We know what's going on in the database, and we see that we can click on Products from Suppliers and then see just suppliers of exotic liquids have these products. Let's go to Products, click Edit. You notice that we also have validation. So we know that we must have a product name. Our Boolean turned into a checkbox. Our relationships turned into comma boxes. And you might immediately think that all of this was cogent so then you'd expect to go in and look in the Dynamic Data folder and think that there would be a Products page and a Categories page, but in fact this is all templating rather than code generation. So it's dynamic templating that looks like code generation based on this information that's in the model. Remember how I pointed out what was going on in the URL there? We said, products/list. This is where the routing thing becomes so interesting. We're passing in the name of the table, and then the name of the action, that action might be list edit, list details, taking all of the CRUD—create, read, update, and delete— and applying it then to templating. We see our available actions in this case are list, details, edit, and insert. We go over to the Solution Explorer, and we open up Page Templates. We see that there is a page for each of those actions. So in the instance of product/list we've got a list page. But there is nothing about products in this page. All that information is being loaded from Metadata. Notice the big <h2> at the top of the page. We say, "Table.DisplayName." This is, again, part of the metamodel— in this case, metatable. So this page is being reused for everything in the site. If I just add something [Hi this is Scott] and hit F5. I made a change to this template [silence] and now I can see that my changes appeared everywhere. We'll see in future, "How to" videos how we can have custom templates for specific tables, how we can change the look and feel of the entire site, add business logic validation, as well as adding Dynamic Data to an existing application. Stay tuned. [♪ music ♪] [Microsoft] []

Video Details

Duration: 6 minutes and 19 seconds
Country: United States
Language: English
License: All rights reserved
Genre: None
Views: 6
Posted by: neudesicasp on Sep 20, 2013

In this short introduction, you create a complete Dynamic Data application in minutes using scaffolding, and in the process learn about Dynamic Data.

Caption and Translate

    Sign In/Register for Dotsub to translate this video.