One of the common questions that gets asked in the RIA Services Forum is how to add additional tables to a DomainService. One of the best practices that has been developed by the RIA Services community is using partial classes to spread a DomainService across multiple files with one Entity in each partial class file. Here are the steps on how to do this.
I am starting with Shawn Wildermuth’s MVVM project since he has multiple tables. Here is what the EDMX looks like:
First you need to add a new DomainService
I am using a naming standard here of EntityName.DomainServiceName
After adding the DomainService the wizard will appear
One of the nice features of the wizard is that you can change the name of the DomainService. We are going to take advantage of that to remove the entity name. Here is what the wizard looks like once we have completely filled it in. i have outlines what changed in red.
UPDATE: The DomainService wizard no longer allows you to change the name of the DomainService from within the wizard. You will need to edit the file manually after the wizard completes instead
After pushing OK this is what the project will look like
Finally we need to modify the DomainService to add a partial to the class definition
Repeat this process for any additional entities you want in your domain service. The only difference is that you will also need to remove the [EnableClientAccess()] attribute from all other partial class files
Setting up your project using partial class makes it easy to add additional tables. If you want to regenerate an entity due to database changes then you will need to comment out the existing code and recompile first. The wizard will not regenerate metadata that already exists in the project.