隐式转换类型
本文关键字:类型 转换 | 更新日期: 2023-09-27 18:21:50
我在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类文件中没有错误,我使用相同的查询来检索其他项目中的记录,它运行良好,不知道为什么它在这里不工作。
您在每个示例中对泛型参数使用不同的大小写-GetListKeys()
中的IList<QuestionHint>
和PopulateQuestion()
中的IList<Model.questionhint>
。我猜这些是指名称相似但不同的类型。