Attribute-based dynamic LINQ query

dynamic-linq

Question

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.

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

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

1
1
2/8/2009 3:37:14 AM

Popular Answer

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?

1
2/8/2009 5:56:52 AM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow