1

have the following in my project, written in VB.NET:

 Dim items = From item In rssFeed.Elements("forecast").Elements("tabular").Elements("time") _
                    Select New WetherItem With {.time=item.Element("windDirection").Attribute("code").Value }

How is this written in C #?

I have tried the following ...

XElement rssFeed = XElement.Load(@"http://www.yr.no/sted/Norge/Rogaland/Karm%C3%B8y/Torvastad/varsel.xml");
var items = from item in rssFeed.Elements("forecast").Elements("tabular").Elements("time")
select new WetherItem { .time=item.Element("windDirection").Attribute("code").Value };

But I get the error message from

rssFeed.Elements("forecast").Elements("tabular").Elements("time")

Error 5 Could not find an implementation of the query pattern for source type 'System.Collections.Generic.IEnumerable'. 'Select' not found. Are you missing a reference or a using directive for 'System.Linq'? c:\users\\documents\visual studio 2012\Projects\Database1\Database1\SqlStoredProcedure1.cs 32 30 Database1

I have reference to System.XML.Linq and System.Data.Linq

1
  • 1
    As a side note: In VB, you can shorten this to From item In rssFeed.<forecast>.<tabular>.<time> Select New WetherItem With {.time = item.<windDirection>.@code}. Commented Dec 17, 2012 at 9:37

3 Answers 3

2

In the C# code file on top you will see the using statements, in there add:

using System.Linq;
using System.Xml.Linq;

Also remove . from .time in your select statement, if the property name is time

Sign up to request clarification or add additional context in comments.

3 Comments

I run. NET 4.5, and Target Platform to SQL Server 2012. I can not find System.Linq in the reference list. By the way this is a SQL CLR
You need to add reference to System.Core.dll from C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5, you may see this: social.msdn.microsoft.com/Forums/en/vstsdb/thread/…
--------------------------- Microsoft Visual Studio --------------------------- A reference to 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Core.dll' could not be added. This component is already automatically referenced by the build system. --------------------------- OK ---------------------------
0

Remember to add using statements at the top of the file, and your query in c#:

var items = from item in rssFeed.Elements("forecast".Elements("tablular").Elements("time")
            select new WetherItem { 
                           time = item.Element("windDirection").Attribute("code").Value
                       };

1 Comment

I have now :) Error 4 Could not find an implementation of the query pattern for source type 'System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement>'. 'Select' not found. Are you missing a reference or a using directive for 'System.Linq'? c:\users\<user>\documents\visual studio 2012\Projects\Database1\Database1\SqlStoredProcedure1.cs 34 26 Database1
0

This is a very unusual problem, that even i faced while working on a app, because neither VS clearly specifies what the problem is nor there are proper ans to this problem. One ans, I think may be is :-

Add another reference to your project :- using System.Linq; apart from using System.Xml.Linq;

using System.Linq;
using System.Xml.Linq;

The errors might go & the project will build.


For more help reference this article :-

problem with using refrence to System.Xml.Linq

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.