tags:

views:

18

answers:

1

Hi,

I'm using Scott Gu's dynamic linq library for Linq to XMl. The problem is I don't know how to refer an element itself value inside of the dynamic query.

What I want to do is as follows:

var doc = XDocument.Load("test.xml");
var ret = doc.Descendants("Row").Where(x => x.Element("ID").Value == "2").ToList();

I want to replace the where clause to dynamic linq, but I don't know how I should rewrite it. I tried as follows:

var ret = doc.Descendants("Row").Where("Element(""ID"").Value == @0", "2").ToList();

But it gives me an error saying "There is no property named Element" or something.

Could anyone please tell me how to do that?

Thanks in advance, Yoo

A: 

Okay, I did a trick. It's not great but works. It might cause a performance problem, but for now, it's okay.

var doc.Descendants("Row").Select(x => x.Element("ID").Value).Where("Value == @0", "2").Select(x => x.Parent).ToList();

If you have a better solution, please post it here.

Thanks, Yoo

Yoo Matsuo