0

我在 ria-service 中使用了三个类:

首先是响应类:

[DataContract]
public class ValidationResponseContainer
{
    [DataMember]
    public string EntityId { get; set; }

    [DataMember]
    public bool IsWarning { get; set; }

    [DataMember]
    public string ConstraintName { get; set; }

    [DataMember]
    public IEnumerable<string> Fields { get; set; }
}

其次是 KeyValuePair<> 之类的东西:

[DataContract]
public class FieldValueContainer
{
    [DataMember]
    public Guid ConstraintId { get; set; }

    [DataMember]
    public string FieldName { get; set; }

    [DataMember]
    public string Value { get; set; }
}

三是要求:

[DataContract]
[KnownType(typeof(FieldValueContainer))]
public class ValidationRequestContainer
{
    [DataMember]
    public string EntityId { get; set; }

    [DataMember]
    public string TableName { get; set; }

    [DataMember]
    public IEnumerable<FieldValueContainer> FieldValues { get; set; }

    public ValidationRequestContainer()
    {
        FieldValues = new List<FieldValueContainer>();
    }
}

部署我的项目后,我在 EventLog 中收到一个错误:

Exception System.Runtime.Serialization.InvalidDataContractException Type 'System.Linq.Enumerable+WhereSelectEnumerableIterator`2[_2020vision.Infrastructure.FieldValueContainer,System.String]' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute.  If the type is a collection, consider marking it with the CollectionDataContractAttribute.  See the Microsoft .NET Framework documentation for other supported types.
   at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.ThrowInvalidDataContractException(String message, Type type)

我的数据合同类有什么问题?

4

0 回答 0