Json ASP.NET Web API OData能否返回非集合属性?
我有以下课程:Json ASP.NET Web API OData能否返回非集合属性?,json,asp.net-web-api,odata,Json,Asp.net Web Api,Odata,我有以下课程: public class WeeklyReport { public IEnumerable<DailyReport> DailyReports { get; set; } public int? TotalReport { get { return DailyReports.Sum(x => x.ReportId);
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; }
}
是否有方法将ASP.NET Web API OData设置为同时返回WeeklyReport.TotalReport和WeeklyReport.Title
谢谢 我复制了这个问题。我相信您正在使用ODataConventionModelBuilder构建Edm模型。默认情况下,构建器仅添加具有公共get并设置为Edm模型的属性。在我添加了一个无操作集之后,问题就解决了。你可以试一试
public class WeeklyReport
{
public IEnumerable<DailyReport> DailyReports { get; set; }
public int? TotalReport
{
get
{
return DailyReports.Sum(x => x.ReportId);
}
set{}
}
public string Title
{
get
{
return "Weekly Report";
}
set{}
}
}
公共类每周报告
{
公共IEnumerable DailReports{get;set;}
公共综合报告
{
得到
{
返回DailReports.Sum(x=>x.ReportId);
}
集合{}
}
公共字符串标题
{
得到
{
返回“周报”;
}
集合{}
}
}
public class WeeklyReport
{
public IEnumerable<DailyReport> DailyReports { get; set; }
public int? TotalReport
{
get
{
return DailyReports.Sum(x => x.ReportId);
}
set{}
}
public string Title
{
get
{
return "Weekly Report";
}
set{}
}
}