不能在 linq to xml 的 where 中使用 DescendantNodes

cant use DescendantNodes in where in linq to xml

我有一个 class 和 xml 字段,如下所示:

Public System.Xml.Linq.XElement ProductAttributeXML {get;set;}

我有如下查询:

var query = (from product in db.ProductAttributeCombinations
                     where product.ProductAttributeXML.DescendantNodes().Count()>0
                     select product

                         );
        var x = query.ToList();

但是当 运行 项目和 ToList() 我得到这个错误:

Method 'System.Collections.Generic.IEnumerable`1[System.Xml.Linq.XNode] DescendantNodes()' has no supported translation to SQL.

我该怎么做?

DescendantNodes() 无法转换 SQL function。我想,如果你用 ToList() 获取数据,这个函数在代码端工作。请试试这个:

 var query = (from product in db.ProductAttributeCombinations.ToList()//add ToList() here                 
              where product.ProductAttributeXML.DescendantNodes().Count()>0
              select product
              );