Question about LinQ (LinQ to Sql)

R

Rich P

I have already heard that LinQ to Sql will be replaced by LinQ to
Entities or something like that. My question is below: that the whole
concept of LinQ whatever -- it is supposed to be better than or provide
some enhancement to the DataAdapter / Sql (tSql) model. I am sure that
there is some benefit provided by LinQ (or the idea behind it) - or
people would not be using it. What is the benefit of LinQ (or the idea
behind it) ?

Here is a linQ query and below that a DataAdapter query
-------------------------
DataClasses1DataContext dc = new DataClasses1DataContext();

var q =
from a in dc.GetTable<Order>()
where a.CustomerID.StartsWith("A")
select a;

dataGridView1.DataSource = q;
----------------------------

string Sql = "Select * From Order
Where CustomerID Like 'A%';
DataAdapter1.SelectCommand.CommandTest = Sql;
DataAdapter1.Fill(ds, "tbl1");
datagridview1.Datasource = ds.Tables["tbl1"];

Is LinQ (or the idea behind it) just less typing - or is the benefit
seen more in web applications? Or does LinQ (or the idea behind it) do
or supposed to do something that can't be done with DataAdapters - like
say - query data inside of a dataset in an application? Once I
understand what the idea of LinQ is supposed to do -- it will all make
sense to me.

Thanks



Rich
 
G

Göran Andersson

Rich said:
I have already heard that LinQ to Sql will be replaced by LinQ to
Entities or something like that. My question is below: that the whole
concept of LinQ whatever -- it is supposed to be better than or provide
some enhancement to the DataAdapter / Sql (tSql) model. I am sure that
there is some benefit provided by LinQ (or the idea behind it) - or
people would not be using it. What is the benefit of LinQ (or the idea
behind it) ?

Here is a linQ query and below that a DataAdapter query
-------------------------
DataClasses1DataContext dc = new DataClasses1DataContext();

var q =
from a in dc.GetTable<Order>()
where a.CustomerID.StartsWith("A")
select a;

dataGridView1.DataSource = q;
----------------------------

string Sql = "Select * From Order
Where CustomerID Like 'A%';
DataAdapter1.SelectCommand.CommandTest = Sql;
DataAdapter1.Fill(ds, "tbl1");
datagridview1.Datasource = ds.Tables["tbl1"];

Is LinQ (or the idea behind it) just less typing - or is the benefit
seen more in web applications? Or does LinQ (or the idea behind it) do
or supposed to do something that can't be done with DataAdapters - like
say - query data inside of a dataset in an application? Once I
understand what the idea of LinQ is supposed to do -- it will all make
sense to me.

One benefit of LINQ lies in it's name - Language Integrated Query - it's
integrated in the compiled code. If you have a syntax error in the LINQ
query you will get the error message when you compile the code. If you
have a syntax error in the SQL query in a string you will not get the
error message until it's executed at runtime.

You can use LINQ To Objects to query any kind of collection in memory.
You can query the items in a List<T> or even the characters in a string:

char u = (
from char c in "asDf"
where Char.IsUpper(c)
select c
).Single();
 
R

Rich P

One benefit of LINQ lies in it's name - Language Integrated Query - it's
integrated in the compiled code. If you have a syntax error in the LINQ
query you will get the error message when you compile the code. If you
have a syntax error in the SQL query in a string you will not get the
error message until it's executed at runtime.

You can use LINQ To Objects to query any kind of collection in memory.
You can query the items in a List<T> or even the characters in a string:

char u = (
from char c in "asDf"
where Char.IsUpper(c)
select c
).Single();


--
Göran Andersson
_____
http://www.guffa.com
<<

Thank you for your explanation. This clarifies the concept of LinQ
significantly for me. Very nice. Is LinQ available in VS2005 or only
VS2008 and higher? I use VS2005 at the workplace and VS2008 at home.

Rich
 
C

Chris

One benefit of LINQ lies in it's name - Language Integrated Query - it's
integrated in the compiled code. If you have a syntax error in the LINQ
query you will get the error message when you compile the code. If you
have a syntax error in the SQL query in a string you will not get the
error message until it's executed at runtime.

You can use LINQ To Objects to query any kind of collection in memory.
You can query the items in a List<T> or even the characters in a string:

char u = (
from char c in "asDf"
where Char.IsUpper(c)
select c
).Single();

--
Göran Andersson
_____http://www.guffa.com
<<

Thank you for your explanation. This clarifies the concept of LinQ
significantly for me. Very nice. Is LinQ available in VS2005 or only
VS2008 and higher? I use VS2005 at the workplace and VS2008 at home.

Rich

*** Sent via Developersdexhttp://www.developersdex.com***

Linq is included in VB.Net 9 and C# 3.0, both of which shipped with
VS2008. They are not available on VS2005

I, too, am limited to using VS2005 at work :(

Chris
 
M

Mr. Arnold

Rich P said:
Is LinQ (or the idea behind it) just less typing - or is the benefit
seen more in web applications? Or does LinQ (or the idea behind it) do
or supposed to do something that can't be done with DataAdapters - like
say - query data inside of a dataset in an application? Once I
understand what the idea of LinQ is supposed to do -- it will all make
sense to me.

http://en.wikipedia.org/wiki/Language_Integrated_Query
http://msdn.microsoft.com/en-us/library/bb425822.aspx
http://en.wikipedia.org/wiki/ADO.NET_Entity_Framework
http://msdn.microsoft.com/en-us/library/bb546158.aspx


__________ Information from ESET NOD32 Antivirus, version of virus signature database 4275 (20090724) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 

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