在过去的几天里,我一直在尝试阅读和测试各种方法,以获取实体框架内实体中的属性(列)并从中检索平均值,然后将其传递给 JSON。我已经接近了几次,但总是失败。最后,当我有 JSON 时,我想以缩进格式返回它,以便在 JQuery 可视化库中使用。
我的控制器在这里:
public virtual JsonResult GetData()
{
var result = new FactSurveryResultsQueries().GetAverages();
return new JsonResult { JsonRequestBehavior = JsonRequestBehavior.AllowGet, Data = result };
}
这是我的视图模型:
namespace Provider.Models
{
public class FactSurveyResultsViewModel //: BaseGraphViewModel
{
public FactSurveyResultsViewModel() { }
//public List<KPIUserControl> customerSatisfactionChart = new List<KPIUserControl>();
////public List<string> customerSatisfactionChart = new List<string>();
//public Dictionary<string, decimal> a { get; set; }
public double? EaseRequestingHelp { get; set; }
public double? TimeReachQualifiedTech { get; set; }
public double? TimeProvideSolution { get; set; }
public double? CompletenessOfSolution { get; set; }
public double? TechAbilityProdKnowledge { get; set; }
public double? HowWellKeptInformed { get; set; }
public double? OverallServiceOpinion { get; set; }
}
}
最后,这是我当前的迭代,仅检索一个属性并对其进行平均,尽管当前为空。
namespace Provider.Queries
{
public class FactSurveryResultsQueries
{
public FactSurveyResultsViewModel GetAverages()
{
var result = new FactSurveyResultsViewModel();
using (var db = new ATSNavigatorDBEntities())
{
var thing =
from p in db.Fact_SurveyResults
group p by 1 into a
select new FactSurveyResultsViewModel { EaseRequestingHelp = a.Average(p.EaseRequestingHelp)};
}
return result;
}
}
}
谁能指出我检索一个属性并让它从我的控制器作为缩进 JSON 访问,以便我可以使用它,然后我可以将它复制到其他属性?谢谢。