无法隐式转换类型'System.Linq.IQueryable< AnonymousType#1>'到'System.Collections.Generic.IEnumerable [英] Cannot implicitly convert type 'System.Linq.IQueryable<AnonymousType#1>' to 'System.Collections.Generic.IEnumerable

查看:55
本文介绍了无法隐式转换类型'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 is IQueryable<AnonymousType#1> but the model is IEnumerable<operatriceviewmodel>.
Either:
change the type of the model to the non-generic IEnumerable or
use var model = ( from ... select ...) or
change the select to return operatriceviewmodel values.


这篇关于无法隐式转换类型'System.Linq.IQueryable&lt; AnonymousType#1&gt;'到'System.Collections.Generic.IEnumerable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆