我正在尝试将LINQ移动到实体查询,直接使用存储库而不是DbContext。我遇到了其中一个错误的问题:"only primitive types ('such as Int32, String, and Guid') are supported in this context)"
这就是我正在尝试的:
var data = from SurveyResponseModel in surveyResponseRepository.Query
group SurveyResponseModel by SurveyResponseModel.MemberId into resultCount
select new ResultsViewModel()
{
MemberId = resultCount.Key,
PatientFollowUpResult = surveyResponseRepository.Query.Count(r => r.PatientFollowUp),
PatientFollowUpResultPct = (int)Math.Round(((decimal)surveyResponseRepository.Query.Count(r => r.PatientFollowUp) / (decimal)totalResponsesResult) * 100),
ChangeCodingPracticeResult = surveyResponseRepository.Query.Count(r => r.ChangeCodingPractice),
ChangeCodingPracticeResultPct = (int)Math.Round(((decimal)surveyResponseRepository.Query.Count(r => r.ChangeCodingPractice) / (decimal)totalResponsesResult) * 100),
EnhanceDiagnosticAcumenResult = surveyResponseRepository.Query.Count(r => r.EnhanceDiagnosticAcumen),
EnhanceDiagnosticAcumenResultPct = (int)Math.Round(((decimal)surveyResponseRepository.Query.Count(r => r.EnhanceDiagnosticAcumen) / (decimal)totalResponsesResult) * 100)
}
这是我的SurveyResponseModel:
public class SurveyResponseModel
{
[Key]
public int ResponseId { get; set; }
public int MemberId { get; set; }
public int ProgramId { get; set; }
// "If yes, what changes did you make? Mark all that apply."
[DisplayName("Did you make any changes in your practice, research, or administration activities as a result of participating in this CME activity?")]
public string CmeChanges { get; set; }
[DisplayName("Better patient follow-up")]
public bool PatientFollowUp { get; set; }
[DisplayName("Change my coding practice")]
public bool ChangeCodingPractice { get; set; }
[DisplayName("Enhance my diagnostic acumen")]
public bool EnhanceDiagnosticAcumen { get; set; }
}
这是显示数据的ViewModel:
public int MemberId { get; set; }
public int ProgramId { get; set; }
// "If yes, what changes did you make? Mark all that apply."
[DisplayName("Did you make any changes in your practice, research, or administration activities as a result of participating in this CME activity?")]
public string CmeChangesResult { get; set; }
[DisplayName("Better patient follow-up")]
public int PatientFollowUpResult { get; set; }
public int PatientFollowUpResultPct { get; set; }
[DisplayName("Change my coding practice")]
public int ChangeCodingPracticeResult { get; set; }
public int ChangeCodingPracticeResultPct { get; set; }
[DisplayName("Enhance my diagnostic acumen")]
public int EnhanceDiagnosticAcumenResult { get; set; }
public int EnhanceDiagnosticAcumenResultPct { get; set; }
在存储库中查询成员:
public IQueryable<SurveyResponseModel> Query
{
get
{
return dbSet.AsQueryable<SurveyResponseModel>();
}
}