tags:

views:

1012

answers:

3

I am using LINQ to XML. I want to use an equivalent of sql's <> operator in the where clause below....

var myBooks = from book in xDoc.Descendants("BOOKOB") 
              where book.Element("AUTHOR").Value

Please help!

+4  A: 

Isn't != working?

Cyril Gupta
A: 

You should be able to use != for not equal and == for equal to.

Corey Sunwold
+1  A: 

As others have said, you can use != perfectly easily - don't forget that even when you're using LINQ, you're writing C#, not SQL.

You need to provide a value for it not to be equal to, of course, along with a select clause:

var myBooks = from book in xDoc.Descendants("BOOKOB") 
              where book.Element("AUTHOR").Value != "Jeff Atwood"
              select book;

For simple queries like this, I usually find "dot notation" simpler to read:

var myBooks = xDoc.Descendants("BOOKOB")
                  .Where(b => b.Element("AUTHOR").Value != "Jeff Atwood");
Jon Skeet