2011-08-23 129 views
1

我有一个包含联系人列表的客户。该列表是一个ISet集合。我不能对它做一个Linq查询。你能帮我解决吗?ISet集合上的Linq查询

感谢,

public class Customer 
{ 
    public virtual Iesi.Collections.Generic.ISet<Contact> Contacts { get; set; } 
} 

Customer customer = session.Get(id); 
customer.Contacts = // Error - customer.Contacts.Where(x => x.Id != contactId); 

更新1

尝试这样做:在where.System.Collections.Generic.IEnumerable” 为 'Iesi.Collections.Generic.ISet' from p in customer.Contacts.AsEnumerable() where p.Id != id select p; 错误。 存在明确的转换(您是否缺少演员?)

回答

0

我假定ISet是System.Collections.Generic.ISet<T>

System.Linq添加使用语句,并可能引用System.Core.dll


如果是其他人的根命名空间的东西Iesi可能表示,你可以使用标准的ISet<T>?或者,你可以以某种方式将你的ISet<T>转换为IEnumerable<T>

+1

不,这是从NHibernate的ISet集合 –

4

我相信这个问题已经无关IESI的ISet <牛逼>实现IEnumerable的<牛逼>(它确实,BTW),但得到的答复是,而不是指向在“更新”所提到的转换异常原来的帖子。

线...

customer.Contacts = customer.Contacts.Where(x => x.Id != contactId); 

...其实做(错误地)试图分配一个IEnumerable <联系>(的。哪里(...)运算符的结果)的财产类型ISet <联系人>(Customer类中的.Contacts属性)。

我强烈怀疑这条线就可以了...

IEnumerable<Contact> contacts = customer.Contacts.Where(x => x.Id != contactId); 

...这证明。凡(...)操作符的IESI的ISet <牛逼>但就好了什么。(...)返回的是(当然)IEnumerable <T>。

对于这个工作,你需要在尝试将其分配给customer.Contacts属性之前自IEnumerable <牛逼>到ISet的<牛逼>你。凡(...)操作的结果转换。

+0

我想要删除与ID的联系人,并保持其他人... –