【问题标题】:Getting Error While Converting IEnumerable to System.Data.Objects.ObjectSet将 IEnumerable 转换为 System.Data.Objects.ObjectSet 时出错
【发布时间】:2012-06-15 18:16:53
【问题描述】:

我正在使用 mvc4.0,enityframework 4.2.1,c#,在生成 .EDMX 文件后,我尝试通过以下代码将上下文对象转换为 IEnumerable

       IEnumerable<TransactionsModel> pro = (IEnumerable<TransactionsModel>) x.ToList();

但我收到以下错误

    Unable to cast object of type 'System.Data.Objects.ObjectSet`1[MCLInventory.Models.Projects]' 
    to type 'System.Collections.Generic.IList`1[System.String]'.   

谢谢 Bhanu Prakash Inturi

【问题讨论】:

    标签: c#-4.0 entity-framework-4.1


    【解决方案1】:

    看起来你在 ToList() 调用本身上失败了,而不是演员表。一些建议...

    • 你知道你希望从ToList() 电话中得到什么样的列表吗?如果是这样,请将其放在与演员阵容不同的行上以 IEnumerable&lt;TransactionsModel&gt;

    • 如果您需要先将 x 转换为其他内容,我不会感到惊讶。那么,什么样的对象 x?这与问题有关,错误似乎向我暗示,您认为它是什么和程序认为它是什么并不相同。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-04
      • 1970-01-01
      相关资源
      最近更新 更多