I have extended an Entity Framework 4 entity class with a calculated property in a partial class. This member is not available on the client to which the entities are exposed via WCF RIA Services.
The solution to this problem when using C# appears to be changing the extension of the partial class file from .cs to .shared.cs. I tried this with my VB.Net solution (.vb to .shared.vb) and got a long list of errors. I believe what happened is that the partial class lost its association with the entity on the client - it inherited from object rather than EntityObject.
My best guess is that this is related to the way that VB.Net handles namespaces. Each project has a 'Root Namespace' which is prepended to anything that is defined within a code file. C# has a 'Default Namespace' which is the namespace into which new types are placed by default - via a namespace statement within the file.
The partial class is probably having the client namespace prepended to it which puts it into a different namespace than the entity with which it is associated on the server.
Is there any means of extending an entity in such a way that those extensions are available on the client via WCF RIA Services and VB.Net?
There is a workaround for this issue that depends on some logic within the T4 templates that generate the entity classes.
If(Not String.IsNullOrEmpty(namespaceName)) Then
#>
Namespace <#=namespaceName#>
<#
The entities are generated within the Root Namespace defined at the project level if one is available, and within the Namespace spedified within the EDMX file otherwise (the CodeGenerationTools.VsNamespaceSuggestion method seems to handle this).
Where a Root Namespace is available, the hand-coded partial classes need to be in that namespace to match the generated ones - they have no namespace declaration at the file level. When these these files are 'shared' to the client (via the shared.vb extension), they end up in the client's Root Namespace whereas the generated entities end up in a namespace that consists of the client's Root Namespace plus the servers Root Namespace.
Removing the Root Namespace from the server project and then explicitly declaring the EDMX's namespace within the handcoded, partial classes results in both these shared files and the generated entitites ending up in the same namespace on the client (the client's Root Namespace plus the EDMX's namespace).
Note: The 'ADO.Net EntityObject Generator' template (added using the 'Add Code Generated Item...' context menu item in the EDMX designer) seems to behave differently than the designer's native one. It was not generating a namespace declaration in my tests even if I cleared the Root Namespace at the project level. I am not sure of the reason for this.