使用Attribute的动态LINQ查询

时间:2021-09-04 21:20:23

I have had some success getting the MSFT Dynamic Linq stuff to work, but now I need to create a "Where" clause that includes an Attribute.

我已经取得了一些成功使MSFT Dynamic Linq工作,但现在我需要创建一个包含Attribute的“Where”子句。

The error I get is "No applicable aggregate method 'First' exists"

我得到的错误是“没有适用的聚合方法'第一'存在”

Here is my code:

这是我的代码:

where = "Element(XName.Get(\"procedure\")).Attributes(XName.Get(\"code\")).First() = \"28002\"";

var q2 = doc.Elements().Descendants("vocabularybody").AsQueryable().Where(where);

if (q2 != null && q2.Count() > 0)
foundItems.Add(item);

here is my XML

这是我的XML

<vocabulary>
<vocabularyheader>
<vocabularyid>5</vocabularyid>
<vocabularyname>Scheduled Procedure</vocabularyname>
</vocabularyheader>
<vocabularybody>
<procedure code="28002" type="Surgery"/>
</vocabularybody>
</gazoontvocabulary>

1 个解决方案

#1


I'm not familiar with the Dynamic LINQ library yet but shouldn't you need the equality operator (==) and not the assignment operator (=) for the where clause?

我不熟悉Dynamic LINQ库,但是你不应该为where子句需要等于运算符(==)而不需要赋值运算符(=)吗?

#1


I'm not familiar with the Dynamic LINQ library yet but shouldn't you need the equality operator (==) and not the assignment operator (=) for the where clause?

我不熟悉Dynamic LINQ库,但是你不应该为where子句需要等于运算符(==)而不需要赋值运算符(=)吗?