I am using WCF RIA Services in combination with the Entity Framework 4.0.
To ensure that related objects make it safely to the client, I need to first include them using the ObjectQuery(Of T).Include or DbSet(Of TResult).Include methods within my DomainService. I also need to add the IncludeAttribute to the navigation properties within metadata classes.
I make a single decision to have a related object transferred to the client and am forced to make two changes to implement it which seems a bit redundant.
I am considering making modifications to the T4 templates so that all navigation properties are automatically decorated with the IncludeAttribute.
I was a little worried about entities that were left over from previous requests being unintentionally sent to the client but my understanding is that the DomainService is stateless which should mean that this will not be the case, right?
The point of the “DomainService” name is that it is the stateless
object that represents a specific domain that is characteristic of my
application.
Another approach that I have seen was to automatically apply Include attributes to any metadata files within the project. I would still need to create the metadata files though.
Are there any other dangers that I am not seeing? Is there a better way to achieve the same effect?
I modified the EDMX T4 template to apply the IncludeAttribute automatically and it is working as expected.
One advantage of manually applying the attributes that I identified along the way was that you are able to control the volume of code that is generated on the client. Entities that are used only on the server can be excluded.
This was not an issue in my case.