Requirements
This article is detail how to get up and running with ASP.NET Dynamic Data 4.0 Preview 3 and Tools, in particular to be able to use the DomainService template provided in the ASP.NET Dynamic Data 4.0 Preview 3.
So download the above Unzip and Install where necessary.
See David Ebbo’s presentation at MIX09 here Microsoft ASP.NET 4.0 Data Access: Patterns for Success with Web Forms to view online or to download.
As I said in my previous post it really is worth a watch.
Using the Sample as a Template
There are two ways you may want to do this as a:
- ASP.NET Web Application
- ASP.NET Web Site
Option 1.
See David Ebbo’s article here Using a DomainService in ASP.NET and Dynamic Data where he explains most of what you need to know.
- Copy the Default project of your preference to the projects folder
- DefaultDomainServiceProject
- DefaultEFProject
- DefaultProject
- Rename appropriately
- Rename the folder to say “MyPreview Project”
- Rename the Project file say “MyPreview Project”
- Edit the project file in an XML editor, I delete the following lines (as they attempt to copy the Northwind DB and if you move the project or delete the App_Data folder you will get build errors)
<Target Name="SetUpDatabase" Condition="!Exists('$(TargetAppDataPath)\NORTHWND.MDF')">
<!-- Copy mdf file –>
<Copy SourceFiles="$(DatabaseSourcePath)\NORTHWND.MDF" DestinationFolder="$(TargetAppDataPath)" /> </Target>
<Target Name="AfterBuild"> <CallTarget Targets="SetUpDatabase" />
</Target>
- You are now done and ready to go.
Note: These are the correct references for the Preview assemblies.
All the Item outlined in
RED should be referenced from the CommonFiles folder all the rest if the are missing you would add them the normal way.
Option 2.
Is a bit more tricky and I’ve covered this in several previous articles see here Adding Dynamic Data Previews to a New or Exiting Dynamic Data Website the main this is the name spaces you’ll just have to check each of the projects to see what they are:
Figure 1 – The three Default Project types for Dynamic Data.
UPDATE: You cannot use a file based website with this build, only because the DomainService wizard is not available, you could do it manually of create your service in a Web Application Project and then copy etc, but I thought that was too much messing about
You can use any of the three above to start a new project, but the one I'm most interested in is the DefaultDomainServiceProject this is the one David uses in his Session at MIX09
Adding a DomainService to the DefaultDomainServiceProject
First you will need to add your data model you can use one of several.
Figure 2 – A Scalable Pattern (unashamedly swiped from Nikhil’s blog)
As you can see from the above diagram copied from Nikhil Kothari’s blog we can have virtually any data source and you can see from David Ebbo’s session at MIX09 where he connecto Azure services and also Nikhil’s session mentions several also. It also has a nice separation of client code from database code, so if we change the DB we only have to change the App Logic (Domain Service) and not all the dependant client code. :D
And now the adding the Domain Service
First we need to add a data model and in this case I’m going to add an Entity Framework modem instead of my usual Linq to SQL using Northwind into the Models folder.
So I’m going to add Categories Products and Suppliers as per David's demo.
Figure 3 – Categories, Products and Suppliers
Note: Do a quick build before launching the Domain Service dialogue (this is a minor undocumented feature :)
Then right click the DomainServies folder and click Add->New Item…
Figure 4 – Adding the DomainService
Choose the Domain Service Class
Give it a name like NW I like to keep it short when I doing a demo.
Figure 5 – Adding the DomainService
- Enable client access Only required for Silverlight at the moment.
- Which tables from the Model to include.
- Whether to add full CRUD operation
- This generates the Metadata Partial Classes for us :D (Thanks guys this is GREAT)
Now you add the DomainService name into the Global.asax file like we did with Linq to SQL or Entity Framework and we are away.
Happy coding.