Martin Ch
Martin Ch

Reputation: 1367

Query xml with linq

I am trying to query some informations from xml with linq but I am getting error like this - Yes I have defined - using System.Linq Could you tell me, where is a problem? Thanks

Error 1 Could not find an implementation of the query pattern for source type 'urn.P.IEEE.Item1671.Item2.Item2008.Item02.InstrumentDescription.InstrumentDescription'. 'Select' not found. D:\Documents and Settings\e539951\my documents\visual studio 2010\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 28 36 WindowsFormsApplication1

InstrumentDescription test = InstrumentDescription.Load(openFileDialog1.FileName);
 var query = from b in test
             select  new {  b.Identification };

Upvotes: 0

Views: 290

Answers (2)

svick
svick

Reputation: 244757

In your code test represents just the root element of the document, so you can't use LINQ on it – it's not an sequence.

What you should do depends on how your XSD looks like. For example, if there can be multiple Identification elements under the root InstrumentDescription element, then just accessing test.Identitication gives you the list.

Upvotes: 1

AllenG
AllenG

Reputation: 8190

You're handling InstrumentDescription instead of an XDocument so it's probably that you need to make sure you InstrumentDescription class is IQueryable.

If you're actually wanting to do Linq against your XML, you either need to load it in as a dataset, or use Linq2XML (using System.Xml.Linq).

See more here. http://msdn.microsoft.com/en-us/library/system.xml.linq.aspx

Upvotes: 0

Related Questions