我在 WPF 中这样做,我正在使用 entity-framework 。
这是我的 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 类文件中没有错误,我使用相同的查询来检索另一个项目中的记录并且它运行良好,不知道为什么它在这里不起作用。