0

我正在尝试将 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)
    }

这是我的调查响应模型:

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>();
            }
        }
4

0 回答 0