0
votes

I am using EntityFramework Code First 5 and I have my data model.

Example:

[Table("Contract"]]
public class Contract
{
    ...

    [ForeignKey("SomeKey")]
    //[Include]
    public virtual BusinessPartner BP
    {
    ...
    }
}

The data model is currently used by WPF client and it works great. Now I am writing a Silverlight client and using the same model. To acces the database I am using RIA Services. It worked great in silverlight until I had to add some RIA annotations like [Include] (it is commented in the above example).

The problem is that we are using .NET 4 Client Profile in our data model and we cannot change it. But RIA annotations are in System.ServiceModel.DomainServices.Server namespace which requires .NET 4 or .NET 4.5.

So if I add RIA [Include] annotation the model does not compile anymore.

Is there any way to use RIA annotation attributes witihin .NET 4 Client Profile so I could use the same data model in WPF and Silverlight client?

I have read something about defining those RIA attributes in XML file but I cannot find an example..

Thank you

2
How about creating dummy attributes for the missing Silverlight ones in your WPF project and dummy attributes for any unwanted WPF EF attributes in your Silverlight project? Then you simply annotate everything with both, but they will generate different Metadata in each project. - Gone Coding
The problem is that the .dll file in which the RIA annotations are is not available in .NET 4 Client Profile. It requires .NET 4 or .NET 4.5. I am looking for a way to "separate" the RIA annotation attributes (like [Include]) from a data model which is using a .NET 4 Client Profile - rbo
You seem to be missing the point... you can create your own replacement [Include] and other attributes quite easily to allow it to compile on either platform. If you use the same namespaces as Microsoft for your attribute classes even the using statements will be identical. - Gone Coding

2 Answers

1
votes

I have found a solution to my problem. I have used FluentMetadata, Fluent API for WCF RIA Services that enabled me to define annotations in a different assembly. It was just what I needed. More information about FluentMetadata can be found on the following link

0
votes

If it worked for WPF and works fine in Silverlight the only thing you need is to create your own dummy attribute for you WPF application which will mimic IncludeAttribute from RIA to get it compiled. To achieve that you need to place the attribute into same namespace where it is in RIA.

namespace System.ServiceModel.DomainServices.Server 
{
    // Just put this into your WPF app :)
    [AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field, AllowMultiple = true, Inherited = true)]
    public class IncludeAttribute : Attribute {}
}