在 WCF Web API Preview 6 上,在我的一项服务中,我使用了直接来自 EF 4.2 的对象,但出现以下错误:
无法序列化 System.Collections.Generic.ICollection`1[[DataAccess.SqlServer.AccommProperty, DataAccess, Version=1.0.4350.30311, Culture=neutral, PublicKeyToken=null]] 类型的成员 DataAccess.SqlServer.Resort.AccommProperties,因为它是界面。
这是我的服务代码:
[WebGet]
public HttpResponseMessage<IQueryable<DataAccess.SqlServer.Resort>> GetAll() {
var resorts = _resortRepo.GetAll(
ApprovalStatus.Approved
);
var resortsResponse =
new HttpResponseMessage<IQueryable<DataAccess.SqlServer.Resort>>(resorts);
resortsResponse.Content.Headers.Expires = new DateTimeOffset(DateTime.Now.AddHours(6));
return resortsResponse;
}
以下是我试图在上面公开的 Resort 类:
public partial class Resort
{
public Resort()
{
this.AccommProperties = new HashSet<AccommProperty>();
this.ResortDetails = new HashSet<ResortDetail>();
}
public int ResortID { get; set; }
public int DestinationID { get; set; }
public System.Guid ResortGUID { get; set; }
public Nullable<int> SecondaryID { get; set; }
public string ResortName { get; set; }
public Nullable<bool> IsApproved { get; set; }
public string ResortType { get; set; }
public virtual ICollection<AccommProperty> AccommProperties { get; set; }
public virtual Destination Destination { get; set; }
public virtual ICollection<ResortDetail> ResortDetails { get; set; }
}
就像错误消息说的那样,我无法序列化 interface。但是我应该怎么做我所有的 EF 对象呢?