I have a Report
class in my web api project:
[KnownType(typeof(Employee))]
[DataContract]
public class Report
{
[DataMember]
public int Id { get; set; }
public string ManagerId { get; set; }
public string EmployeeId { get; set; }
[DataMember]
public virtual Employee Manager { get; set; }
[DataMember]
public virtual Employee Employee { get; set; }
}
If virtual
is in the method signature I get the following exception:
Type 'System.Data.Entity.DynamicProxies.Report_1FFC700B8A805A61BF97A4B9A18D60F99AAA83EE08F4CA2E2454BADA9737B476' with data contract name 'Report_1FFC700B8A805A61BF97A4B9A18D60F99AAA83EE08F4CA2E2454BADA9737B476:http://schemas.datacontract.org/2004/07/System.Data.Entity.DynamicProxies' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.
If it isn't everything works. What am I missing?
Edited to include object retrieval code
ApiController
[ResponseType(typeof(IEnumerable<Report>))]
public IHttpActionResult GetLogs([FromUri] string id)
{
return Ok(_loggingService.GetReportsByEmployeeId(id));
}
Service
public IQueryable<Report> GetReportsByEmployeeId(string employeeId)
{
return _reports.GetAll().Where(x => x.ManagerId.Equals(employeeId) || x.EmployeeId.Equals(employeeId));
}
Repository
public IQueryable<T> GetAll()
{
return _dbSet;
}