无法将类型 IEnumerable 转换为 ObservableCollection...您是否缺少演员表? [英] Cannot convert type IEnumerable to ObservableCollection...are you missing a cast?

查看:20
本文介绍了无法将类型 IEnumerable 转换为 ObservableCollection...您是否缺少演员表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试返回布尔值isAssy"为真的实体:

I'm trying to return entities where the bool "isAssy" is true:

 public ObservableCollection<MasterPartsList> ParentAssemblyBOM
 {
      get {return this._parentAssemblyBOM.Where(parent => parent.isAssy == true); }
 }

但是整个语句都用红色下划线表示我不能将类型 IEnumerable 转换为 ObservableCollection...你错过了演员表吗?"

but the entire statement is underlined in red stating that I cannot "convert type IEnumerable to ObservableCollection...are you missing a cast?"

推荐答案

ObservableCollection 有一个 重载构造函数 接受 IEnumerable 作为参数.假设您的 Linq 语句返回 MasterPartsList 项的集合:

ObservableCollection<T> has an overloaded constructor that accepts an IEnumerable<T> as a parameter. Assuming that your Linq statement returns a collection of MasterPartsList items:

public ObservableCollection<MasterPartsList> ParentAssemblyBOM
{
    get 
    {
        var enumerable = this._parentAssemblyBOM
                             .Where(parent => parent.isAssy == true);

        return new ObservableCollection<MasterPartsList>(enumerable); 
    }
}

这篇关于无法将类型 IEnumerable 转换为 ObservableCollection...您是否缺少演员表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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