0

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

4

2 回答 2

1

我找到了解决我的问题的方法。我使用了 FluentMetadata,即用于 WCF RIA 服务的 Fluent API,它使我能够在不同的程序集中定义注释。这正是我所需要的。有关 FluentMetadata 的更多信息,请参见以下链接

于 2012-06-22T12:18:13.803 回答
0

如果它适用于 WPF 并且在 Silverlight 中运行良好,那么您唯一需要的是为您的 WPF 应用程序创建自己的虚拟属性,该属性将模仿 RIA 中的 IncludeAttribute 以对其进行编译。要实现这一点,您需要将属性放置到它在 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 {}
}
于 2012-06-21T15:49:45.763 回答