0

DbContext を直接使用するのではなく、リポジトリを使用するように LINQ to entities クエリを移動しようとしています。エラーが発生するクエリの 1 つに問題があります。 "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>();
            }
        }
4

0 に答える 0