Wcf数据服务反射提供者抱怨不相关的类型

时间:2011-11-02 01:34:00

标签: wcf-data-services

我有两项服务,即客户服务和产品服务。它们是独立的,每个都有自己的实体类型。当我将它们分成两个不同的项目时,它们工作正常。但是,当他们在同一个项目中时,当我尝试导航到每个服务URL时,我会收到类似于以下内容的错误。

The server encountered an error processing the request. The exception message is 'Type 'Common.Model.Product' has property 'Category' of entity type. Either this property has no corresponding entity set in the data context or one of its inherited types has a corresponding entity set. Specify IgnoreProperties attribute on the entity type for this property or use a property type that has a corresponding entity set in the data context.'

如果出现此错误,我正在尝试使用naviagate客户服务URL,但它会抱怨客户服务中从不使用或引用的产品服务实体类型。类似地,当我尝试导航产品服务URL时,我收到此错误:

The server encountered an error processing the request. The exception message is 'The property 'Customers' on type 'Common.Model.Branch' is not a valid property. Properties whose types are collection of primitives or complex types are not supported.'

同样,错误是关于在产品服务中使用的EntityType,并且从未在客户服务中使用或引用。

我想重复一遍,如果我将这些服务及其实体类型拆分为不同的项目,那么这两项服务都可以正常运行。

有没有办法解决这个问题?

1 个答案:

答案 0 :(得分:0)

问题在于两种服务的实体类型都来自同一个基类:

[DataServiceKeyAttribute("Id")]
public class BaseEntity : INotifyPropertyChanged
{
    #pragma warning disable 67        // Required by the interface
    public event PropertyChangedEventHandler PropertyChanged;
    #pragma warning restore 67

    public int Id { get; set; }
}

无论出于何种原因(我仍然不太明白为什么),这使得反射提供者遍历每个服务的所有派生类。当我删除此依赖项时,服务开始工作。