无法隐式转换类型'System.Linq.IQueryable< AnonymousType#1>'到'System.Collections.Generic.IEnumerable [英] Cannot implicitly convert type 'System.Linq.IQueryable<AnonymousType#1>' to 'System.Collections.Generic.IEnumerable
本文介绍了无法隐式转换类型'System.Linq.IQueryable< AnonymousType#1>'到'System.Collections.Generic.IEnumerable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好我在尝试这个时遇到了这个错误
Hello I got this error while trying to do this
IEnumerable<operatriceviewmodel> model = null;
model= (
from e in db.Operatrices
join j in db.Operations
on e.Id_Operatrice equals j.Id_Operatrice
select new
{
Id_Operatrice = e.Id_Operatrice,
Nom_Operatrice = e.Nom_Operatrice,
Prenom_Operatrice = e.Prenom_Operatrice,
Designation = j.Designation
}
);
return View(model);
请帮我修理它
Help me please to fix it
推荐答案
假设匿名类型的属性实际上是ViewModel所具有的相同属性,只需在查询中添加一个单词就可以解决问题:
Assuming that the properties of the anonymous type are actually the same properties the ViewModel has, just adding one word to the query should do the trick:
IEnumerable<operatriceviewmodel> model = null;
model= (
from e in db.Operatrices
join j in db.Operations
on e.Id_Operatrice equals j.Id_Operatrice
select new operatriceviewmodel // <--- here
{
Id_Operatrice = e.Id_Operatrice,
Nom_Operatrice = e.Nom_Operatrice,
Prenom_Operatrice = e.Prenom_Operatrice,
Designation = j.Designation
}
);
return View(model);
问题是结果select是IQueryable< AnonymousType#1>
但模型是IEnumerable< operatriceviewmodel>
。
要么:
将模型
的类型更改为非通用IEnumerable
或
使用var model =(from ... select ...)
或
更改选择
返回operatriceviewmodel
值。
The problem is that the result of the select isIQueryable<AnonymousType#1>
but the model isIEnumerable<operatriceviewmodel>
.
Either:
change the type of themodel
to the non-genericIEnumerable
or
usevar model = ( from ... select ...)
or
change theselect
to returnoperatriceviewmodel
values.
这篇关于无法隐式转换类型'System.Linq.IQueryable< AnonymousType#1>'到'System.Collections.Generic.IEnumerable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文