我有一个客户有一个联系人列表。这个列表是一个 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);
更新一
试过这个:from p in customer.Contacts.AsEnumerable() where p.Id != id select p; where.System.Collections.Generic.IEnumerable 错误 到“Iesi.Collections.Generic.ISet”。 存在显式转换(是否缺少强制转换?)
请您参考如下方法:
我相信这个问题与 IESI ISet
这条线...
customer.Contacts = customer.Contacts.Where(x => x.Id != contactId);
...实际上(错误地)尝试将 IEnumerable
我强烈怀疑这条线没问题......
IEnumerable<Contact> contacts = customer.Contacts.Where(x => x.Id != contactId);
...证明 .Where(...) 运算符在 IESI ISet
为此,您需要将 .Where(...) 操作的结果从 IEnumerable
