无法将IEnumerable类型转换为ObservableCollection ...您是否丢失了一个演员? [英] Cannot convert type IEnumerable to ObservableCollection...are you missing a cast?

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

问题描述

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

但整个语句都带有下划线,表示我无法转换类型IEnumerable to ObservableCollection ...你错过了一个演员?

解决方案

ObservableCollection< T> code>有一个重载的构造函数,它接受一个 IEnumerable< T> 作为参数。假设您的Linq语句返回一组 MasterPartsList 项目:

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

返回新的ObservableCollection< MasterPartsList>(可枚举);
}
}


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); }
 }

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

解决方案

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天全站免登陆