keyongtech


  keyongtech > dotnet.languages.* > dotnet.languages.csharp > 07/2009

 #1  
07-24-09, 07:38 PM
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

*** Sent via Developersdex http://www.developersdex.com ***
 #2  
07-24-09, 10:00 PM
Göran Andersson
Rich P wrote:
[..]
> 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();
 #3  
07-24-09, 10:34 PM
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();
 #4  
07-24-09, 10:43 PM
Chris
On Jul 24, 4:34 pm, Rich P <rpng> wrote:
[..]
> _____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
 #5  
07-25-09, 12:46 AM
Mr. Arnold
"Rich P" <rpng123> wrote in message
news:5956
>
> 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
Similar Threads
Linq to XML--Are there code examples that make Linq as easy as SQL? Or how can I convert ths simple pseudo code into real code?

Maybe I shouldn't be using XML for what I want. I want to store some program data and retrieve it easily, iterating through elements grabbing child elements easily and...

LINQ 101 question

In this LINQ example, how do you get at the values within the groupings? string[] anagrams = {"from", "salt", "earn ", "last ", "near ", "form "}; var orderGroups =...

Combination of Linq to sql and Linq to xml

Hi folks I am pretty new to linq and in one of my first samples I tried to do the following: In my sample-database I have a table which has some columns and one of them has...

Mixing linq to sql and linq to xml (in linqpad)

Hi group, In my database, I have a table with fields like this : id | title | xml ------------------------------------ 1 | title1 | ...

Linq to SQL - Return DataTable as a result of Linq query

Hi! How to get result od dataTable from Linq query? I have typied DataSet and I want to join couple of tables. And I have a problem with change this result to DataTable...


All times are GMT. The time now is 06:02 PM. | Privacy Policy