0

这是我在类文件中的代码,我如何在我的 xaml.cs 中调用它(后面的代码)?

  //Get all records based on ActivityID and TaskID and Group By ActivityID , TaskID , QuestionNo.
    public IList<QuestionHint> GetRecords1(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
        }).Where(q => q.TaskID == listTask && q.ActivityID == listActivity)
            //.Take(50)
          .ToList();

        return lstRecords;
    } 

 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 

        }

这就是我尝试在 WPF 后面的 xaml.cs 代码中使用此方法的方式:

IList<QuestionHint> lstQuestionHints = qh.GetRecords(taskID, activityID);

但是错误说找不到 QuestionHint 但我已经像这样声明它:

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

我正在使用带有 lambda 表达式的实体框架,DAOQuestionHint 是类文件的名称。

4

1 回答 1

1

编译器希望您为类型(而不是真正声明的 for )放置适当using的指令,或者使用它的全名,如QuestionHintDAO.DAOQuestionHintSomeNamespace.QuestionHint.

最简单的添加方法using是右键单击QuestionHint并从上下文菜单中选择“解决”。

于 2013-07-17T05:21:33.540 回答