Requirements
- ASP.NET Dynamic Data 4.0 Preview 3
- Silverlight 3 Beta Tools for Visual Studio (Recommended by Scott Hunter)
- .NET RIA Services (Recommended by David Ebbo and Scott Hunter) Required.
- Visual Studio 2008 with SP1 installed (From Web Developer through Team Suit)
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)
- You are now done and ready to go.
<!-- Copy mdf file –>
<Copy SourceFiles="$(DatabaseSourcePath)\NORTHWND.MDF" DestinationFolder="$(TargetAppDataPath)" /> </Target>
<Target Name="AfterBuild"> <CallTarget Targets="SetUpDatabase" />
</Target>
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.
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
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.
7 comments:
Check out the sample, will you ever be able to do a update operation with foreign key involved?
Sorry not sure what you mean?
Steve :D
Hey Steve, thank you very much for posting this, i am sure many would appreciate it.
Chris
It's quite a sophisticated subject, so I'm not sure if anybody understands it...
You are correct, I will try and do a more clear version soon :)
Steve
Hi Steve
I admire your generosity in time in sharing your ideas.
In a previous web page you have said that you are looking into doing the Cascading Filters using Domain Service for Dynamic Data. I have tried unsuccessfully to convert your DD_CascadingFiltersFutures (EF) into a Domain Service Dynamic Data Project.
Could you let me know when this will be available.
Hi I will be doing this at some point but I don't have the time to dedicate it at the moment. We all have to earn a crust :)
Hopefully I will find someone to pay me to write article and do support... :)
Steve
Post a Comment