Linq - basic simple Answer

R

raulavi

Hi all:
after reading different places/sites about linq... I ran into these questions:

1. What framework do we need to run linq ?
(does it depend on what version of visual studio we have?)
how about vs2008?
is it different name space or framework for linq xml or linq sql? (
2. do we need to have references to what linq's dlls. or namespaces?
system core?
3. what name spaces are needed?
4. what is the earliest framework where linq can run?
5. C# vs2008 what else?

thanks for taking the time to clearing this out.
 
J

Jon Skeet [C# MVP]

after reading different places/sites about linq... I ran into these questions:

1. What framework do we need to run linq ?

That depends on what you mean by LINQ. LINQ to Objects can be run
in .NET 2.0 so long as you have a suitable implementation, such as
LINQBridge (search to find it).
LINQ to XML (and other out-of-process LINQ providers) require
expression trees, which in turn require .NET 3.5.
   (does it depend on what version of visual studio we have?)
   how about vs2008?

To be running LINQ "properly" (i.e. with real language integration)
you need to be using C# 3 or VB9, both of which require VS 2008 (or a
text editor with .NET 3.5 installed).
   is it different name space or framework for linq xml or linq sql? (
2. do we need to have references to what linq's dlls. or namespaces?
   system core?

You need System.Core for various bits (assuming you want to use the
built-in providers). I can't remember whether the LINQ to XML and LINQ
to SQL classes live - but you could look them up in MSDN.
3. what name spaces are needed?

Again, that depends on the provider you're using. For LINQ to Objects,
you just need System.Linq.
4. what is the earliest framework where linq can run?

See answer to question 1.
 5. C# vs2008 what else?

What do you mean?

Jon
 
R

raulavi

Thanks Jon:
That depends on what you mean by LINQ. LINQ to Objects can be run
in .NET 2.0
lets start with LinQ to Objects. (net.2.0)
then we need .Net3.5 (correct) to support lambdas to expression trees
(i.e., Expression<TDelegate>)


... LINQ to Objects can be run
in .NET 2.0 so long as you have a suitable implementation, such as
LINQBridge (search to find it).
I read about it. very good dll, limited
allowing you to use C# 3.0's extension methods in Framework 2.0.
http://www.albahari.com/nutshell/linqbridge.html

Again, that depends on the provider you're using. For LINQ to Objects,
you just need System.Linq.

I got project properties to target net3.5 , i added the system.core to the
project's references ,and cannot add my using System.Linq (intellisense does
not show it up) and compiler reported as error , Any clue?

What do you mean?
I meant, anything else to run Linq in C# using visual studio 2008.
but, you already give me the answers, (the clue is that linq is a group of
things
not just a single dll, part of my confusion)


Thanks
(I like the way you anwser everyone's question, you detail answers a little
bit more
Knowing that we want to catch up, thanks for that).




Jon Skeet said:
That depends on what you mean by LINQ. LINQ to Objects can be run
in .NET 2.0 so long as you have a suitable implementation, such as
LINQBridge (search to find it).
I read about it. very good dll, very limited
allowing you to use C# 3.0's extension methods in Framework 2.0.

http://www.albahari.com/nutshell/linqbridge.html
 
J

Jon Skeet [C# MVP]

raulavi said:
lets start with LinQ to Objects. (net.2.0)
then we need .Net3.5 (correct) to support lambdas to expression trees
(i.e., Expression<TDelegate>)
Yes.

I read about it. very good dll, limited
allowing you to use C# 3.0's extension methods in Framework 2.0.
http://www.albahari.com/nutshell/linqbridge.html

It lets you use extension methods (which is the easy bit) *and* it's an
implementation of LINQ to Objects.
I got project properties to target net3.5 , i added the system.core to the
project's references ,and cannot add my using System.Linq (intellisense does
not show it up) and compiler reported as error , Any clue?

No idea, I'm afraid - certainly System.Linq.Enumerable is in the
System.Core assembly, for example.

What error are you getting?

If you set the project to target .NET 3.5, I would expect System.Core
to be in the default set of references, by the way.
I meant, anything else to run Linq in C# using visual studio 2008.
but, you already give me the answers, (the clue is that linq is a group of
things not just a single dll, part of my confusion)

Yes, it's a fairly vaguely defined term, unfortunately. That's why it's
tricky when someone says "I'm using LINQ to do X" but without making it
clear which "flavour" of LINQ they're using :(
Thanks
(I like the way you anwser everyone's question, you detail answers a little
bit more Knowing that we want to catch up, thanks for that).

My pleasure - glad it helps.
 
P

Pavel Minaev

LINQ to XML (and other out-of-process LINQ providers) require
expression trees, which in turn require .NET 3.5.

This isn't quite true, as LINQ to XML in particular does not work with
expression trees - all it does is providing a set of "axis" methods
such as Ancestors() or Attributes(), that return IEnumerable of some
XObject-derived type, which can then be queried using LINQ to Objects
as usual. As such, it is quite possible to implement LINQ to XML on
top of .NET 2.0, in the same manner as LINQbridge.
You need System.Core for various bits (assuming you want to use the
built-in providers). I can't remember whether the LINQ to XML and LINQ
to SQL classes live - but you could look them up in MSDN.

It's System.Xml.Linq.dll and System.Data.Linq.dll, respectively - same
as namespaces.

As I recall, System.Xml.Linq is actually added to a new project
references by default if target is set to 3.5.
 
J

Jon Skeet [C# MVP]

Pavel Minaev said:
This isn't quite true, as LINQ to XML in particular does not work with
expression trees - all it does is providing a set of "axis" methods
such as Ancestors() or Attributes(), that return IEnumerable of some
XObject-derived type, which can then be queried using LINQ to Objects
as usual. As such, it is quite possible to implement LINQ to XML on
top of .NET 2.0, in the same manner as LINQbridge.

You're right, of course. I don't know what I was thinking. Apologies.
Doh!

The same is true of LINQ to DataSets too.
It's System.Xml.Linq.dll and System.Data.Linq.dll, respectively - same
as namespaces.

And LINQ to DataSets is in System.Data.DataSetExtensions.
As I recall, System.Xml.Linq is actually added to a new project
references by default if target is set to 3.5.

Yup - ditto System.Core though, which makes me wonder about raulavi's
follow-up post...
 
T

Tim Jarvis

raulavi said:
I got project properties to target net3.5 , i added the system.core
to the project's references ,and cannot add my using System.Linq
(intellisense does not show it up) and compiler reported as error ,
Any clue?

Did the project originally target 2.0 and then you changed it to 3.5?
if so you probably just need to add the assembly reference manually.

Cheers Tim.
 
R

raulavi

Thanks Tim:
You are right, changed proj from 2.0 to 3.5
but, I got to closed IDE and reopened and did the trick. ODD!!


if so you probably just need to add the assembly reference manually.
manually...what do you mean.
 
T

Tim Jarvis

raulavi said:
Thanks Tim:
You are right, changed proj from 2.0 to 3.5
but, I got to closed IDE and reopened and did the trick. ODD!!

Ah cool, glad it got sorted. I didn't know that VS would auto add the
reference to an updated project after a restart, thats cool as it would
have been a minor PITA otherwise.
manually...what do you mean.

Oh adding an assembly reference manually is just a matter of right
clicking the references entry in the solution explorer and selecting
add reference from the context menu then navigating to the assembly
that you want to add. Though in your case a restart is way better as
you would have been re-adding system assemblies from the later (3.5)
framework directory, much nicer and easier that VS did it for you.

Cheers Tim.

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top