我在ria-service中使用了三个类:
首先是Response类:
[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&lt;&gt;:
[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)
我的datacontract课程出了什么问题?