这是我在类文件中的代码,我如何在我的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是类文件的名称。
答案 0 :(得分:1)
编译器要求您为using
类型添加适当的QuestionHint
指令(不是真正声明的DAO.DAOQuestionHint
),或者使用全名SomeNamespace.QuestionHint.
< / p>
添加using
的最简单方法是右键点击QuestionHint
,然后从上下文菜单中选择“解析”。