隐式转换类型

时间:2013-07-11 04:18:09

标签: c# wpf database entity-framework dao

我在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后面的代码中收到此错误:

  

无法隐式转换类型   &#39; System.Collections.Generic.IList&#39;   到&#39; System.Collections.Generic.IList&#39;。一个   存在显式转换(您是否错过了演员?)

iStellar是该项目的名称。 DAOQuestionHint是CRUD类文件的名称。

CRUD类文件中没有错误,我使用相同的查询来检索另一个项目中的记录并且运行良好,不知道它为什么不在这里工作。

1 个答案:

答案 0 :(得分:2)

您在每个示例中对通用参数使用不同的大小写 - IList<QuestionHint>中的GetListKeys()IList<Model.questionhint>中的PopulateQuestion()。我猜这些都是指同样命名但不同的类型。

相关问题