Home > English > Visual Studio Add-in for Domain Service [Include()] attribute

Visual Studio Add-in for Domain Service [Include()] attribute

Sometimes you don’t have the luxury to develop your applications from a domain centric approach. This means that you need to do reverse engineering of your datamodel and create your entities from it. Luckily we have either the Entity Framework or Linq2Sql to help us out. Since we are targeting Silverlight, we are still not finished as we need to use WCF RIA Services to transport our changes back and forth from the server.

An issue I have with the current workflow when using WCF RIA Services is that anytime the database model changes, we need to do several things:

  1. Update the Entity Framework (.edmx) or Linq2Sql (.dbml) file with the datebase schema changes.
  2. Drop the DomainService that you have created which includes the service file and the .metadata file.
  3. Build the Web project that is hosting your model.
  4. Add a DomainService again.
  5. Add all of the [Include()] attributes into the .metadata file.

Right now this is a very painful experience and whenever I can automate this I will do so. This leads us to the purpose of this post which is a way to at least automate the adding of the [Include()] attribute on the .metadata file. The solution to this was originally posted here and I have modified it slightly to support recursive folders and to work on Visual Studio 2010 RTM.

I created a new solution and selected Extensibility under the “Other Project Types” and then “Visual Studio Add-in” as seen below:

The project template will the create what is shown below except for the MetadataHelper.cs file.

Take some time to review what is in place in the Connect.cs file as well since there is some custom logic to get my MetadataHelper.cs file working correctly.

Basically the purpose of this Add-in is to allow you to update your .edmx or .dbml file and the drop and re-create your DomainService. Once you have done that you will click on the Tools menu in Visual Studio and then select MetadataAddin.

This will cycle through all of your projects in your solutions and all of your folders in your projects. It basically is looking for any .metadata files. Once it finds the file it builds a dictionary of the types of entities exposed through the model by looking for the MetadataTypeAttribute. It then looks for any “EntityCollection” properties or any types that were stored in the dictionary as properties and adds the [Include()] attribute.

Finally, I added code to popup a message box letting me know that it has “Finished executing”.

When the process has finished all of your .metadata files will be loaded and you will be able to review the changes made to the files.

Here is the link to the sample project. I included a README.txt file in the project to show you where you need to put the Add-in once you have successfully built the project.

Hope this helps!

  1. November 11, 2010 at 1:30 am

    What a maddening cycle? Aren’t you worried about losing custom logic in the Domain Service?

    Have you looked at IdeaBlade’s DevForce? [aside: that’s my company and my product]. You don’t worry about this nonsense. You update your EDMX and go. No Domain Service; no includes.

    • November 11, 2010 at 1:54 am


      You are right that it is crazy! I am not worried about losing logic since I always put my logic in a partial class. It has been quite a while since I looked at IdeaBlade’s DevForce. I will take a look at it.



  2. Scott Munro
    August 8, 2011 at 1:37 am

    I am considering automatically applying Include attributes to all of my entities by modifying the edmx T4 templates. Is there any reason that you targeted the metadata files instead? I have this related question on StackOverflow.


    • August 8, 2011 at 12:19 pm

      Hi Scott,

      That would probably be even a better solutions as it removes the dependency on the Add-In. I see nothing wrong with what you are doing and using the T4 templates to get your job done!

      Good luck,


  3. August 18, 2011 at 8:12 pm

    what is the path and membername constructor’s in the include attribute?

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: