【问题标题】:cant use DescendantNodes in where in linq to xml不能在 linq to xml 中使用 DescendantNodes
【发布时间】:2016-04-18 06:58:22
【问题描述】:

我有一个这样的 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() 我得到这个错误:

方法 'System.Collections.Generic.IEnumerable`1[System.Xml.Linq.XNode] DescendantNodes()' 不支持 SQL 转换。

我该怎么做?

【问题讨论】:

    标签: c# xml linq linq-to-xml


    【解决方案1】:

    DescendantNodes() 无法转换 SQL function。我认为,如果您使用ToList() 获取数据,则此函数在代码端有效。请试试这个:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多