On WCF Web API Preview 6, inside one of my services I used the object which directly comes from EF 4.2 and I got the following error:
Cannot serialize member DataAccess.SqlServer.Resort.AccommProperties of type System.Collections.Generic.ICollection`1[[DataAccess.SqlServer.AccommProperty, DataAccess, Version=1.0.4350.30311, Culture=neutral, PublicKeyToken=null]] because it is an interface.
This is the code of my service:
[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;
}
The below is the Resort class which I am trying to expose above:
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; }
}
Like the error message says, I can't serialize an interface. But what am I supposed to do all of my EF objects?