0

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 };
svick
  • 236,525
  • 50
  • 385
  • 514
Martin Ch
  • 1,337
  • 4
  • 21
  • 42

2 Answers2

1

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.

svick
  • 236,525
  • 50
  • 385
  • 514
0

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

AllenG
  • 8,112
  • 29
  • 40