0

私はこれを WPF で行っており、エンティティ フレームワークを使用しています。

これは、CRUD クラス ファイルのクエリ コードです。

 public class QuestionHint
    {
        public int? QuestionNo { get; set; } //change the type accordingly 
        public int? ActivityID { get; set; } //change the type accordingly 
        public int? TaskID { get; set; } //change the type accordingly 
        public string Answer { get; set; }   //change the type accordingly 
        public string QuestionContent { get; set; }   //change the type accordingly 
        public string joined { get; set; }   //change the type accordingly 
        public string joinOption { get; set; }   //change the type accordingly 

    }

        public IList<QuestionHint> GetListKeys(int listTask, int listActivity)
    {
        IList<QuestionHint> lstRecords = context.questionhints.GroupBy(x => new { x.QuestionNo, x.ActivityID, x.TaskID }).ToList().Select(g => new QuestionHint()
        {
            QuestionNo = g.Key.QuestionNo,
            ActivityID = g.Key.ActivityID,
            TaskID = g.Key.TaskID,
            joined = String.Join(" ",
                g.OrderBy(q => q.questionhintID)
                 .Select(i => i.QuestionContent + "[" + i.Answer + "]")),
            joinOption = String.Join(" ",
                   g.OrderBy(q => q.questionhintID)
                    .Select(a => "[" + a.Option1 + "," + a.Option2 + "]"))


        }).Where(x => x.TaskID == listTask && x.ActivityID == listActivity)
            //.Take(50)
    .ToList();

        return lstRecords;
    }

私はこれをコードビハインドで呼び出します:

 private DAO.DAOQuestionHint qh = new DAO.DAOQuestionHint();

    public MainWindow2()
    {
        InitializeComponent();
        PopulateQuestion(1, 5);
    }

    private void PopulateQuestion(int activityID, int taskID)
    {


        IList<QuestionHint> lstQuestionHints = qh.GetListKeys(taskID, activityID); // ERROR

        //codes here...
        }

xaml.cs の背後にあるコードでこのエラーが発生しています:

タイプ 'System.Collections.Generic.IList' を 'System.Collections.Generic.IList' に暗黙的に変換することはできません。明示的な変換が存在します (キャストがありませんか?)

iStellar はプロジェクトの名前です。DAOQuestionHint は、CRUD クラス ファイルの名前です。

CRUD クラス ファイルにエラーはありません。同じクエリを使用して他のプロジェクトのレコードを取得すると、うまく機能します。ここで機能しない理由がわかりません。

4

1 に答える 1

2

IList<QuestionHint>inGetListKeys()IList<Model.questionhint>inの各例で、一般的な引数に異なる大文字を使用していますPopulateQuestion()。これらは、名前が似ているが異なるタイプを指していると思います。

于 2013-07-11T04:22:57.937 に答える