I have the following class:
public class WeeklyReport
{
public IEnumerable<DailyReport> DailyReports { get; set; }
public int? TotalReport
{
get
{
return DailyReports.Sum(x => x.ReportId);
}
}
public string Title
{
get
{
return "Weekly Report";
}
}
}
public class DailyReport
{
public string Office { get; set; }
public string Name { get; set; }
public string Type { get; set; }
public string ReportTo { get; set; }
public DateTime Collection { get; set; }
public int? Leads { get; set; }
}
In one of my method in OData controller, I return IQueryable of WeeklyReport. However, when the OData endpoint is queried, the returned JSON looks something like:
{
"odata.metadata": "http://localhost:546/odata/$metadata#WeeklyReports",
"value": [
{
"DailyReports": [
{
"Office": "002",
"Name": "First Last",
"Type": 10,
"ReportTo": "00002",
"Collection": "2014-03-18T00:00:00",
"Leads": null
},
{
"Office": "002",
"Name": "Agent, ",
"Type": 10,
"ReportTo": "00002",
"Collection": "2014-03-18T00:00:00",
"Leads": null
}
]
},
{
"DailyReports": [
{
"Office": "002",
"Name": "First Last",
"Type": 10,
"ReportTo": "00002",
"Collection": "2014-03-18T00:00:00",
"Leads": null
},
{
"Office": "002",
"Name": "Agent, ",
"Type": 10,
"ReportTo": "00002",
"Collection": "2014-03-18T00:00:00",
"Leads": null
}
]
}
]
Is there a way to set ASP.NET Web API OData to return WeeklyReport.TotalReport and WeeklyReport.Title as well?
Thanks!