[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Should I use SqlCommand's or "Linq to SQL"

Posted on 2009-02-21
8
Medium Priority
?
1,459 Views
Last Modified: 2013-11-07
In all of my previous websites I have worked with MsSQL using the SqlCommand class to interact with the database itself. I have seen a lot of hype about "Linq to SQL". I think that I am okay with the syntax and usage.

Why should I use "Linq to SQL"? What benefits does it have over the SqlCommand approach? Does this mean that my web application is going to be doing all of the query processing? Is it not best to have the SQL server do the hard work?

Or, do you guys recommend another approach?
0
Comment
Question by:numberkruncher
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 27

Accepted Solution

by:
nmarun earned 800 total points
ID: 23703032
One way is to use Stored Procedures with SqlCommand. This way your sql commands are pre-compiled and they are in a separate layer than your .net code. Even if there's a slight change in your table structure, you might not have to change your .net code.

The benefit of using LINQ is the flexibility it offers in creating dynamic types. But the downside would be that you would be passing adhoc queries (slightly less efficient). It's also not sure that you'll find the difference in the performance lag because of passing adhoc queries.

Personally I prefer using Stored Procedures with SqlCommand.
0
 
LVL 15

Assisted Solution

by:aibusinesssolutions
aibusinesssolutions earned 400 total points
ID: 23703895
The main thing about Linq is that you can use it for anything, not just "Linq to SQL", I'm not sure how that one class gets all the hype.  Basically, if you learn to code with LINQ, then you will be more comfortable working with LINQ to SQL, otherwise I would stick to what you are comfortable with.

If you don't know much about LINQ, LINQ stands for Language Integrated Query, you can use it on any enumerable object, meaning you can group by, sort by, filter by, etc. on any enumerable.

Here is an example for working with an Array.
Dim values() As Integer = {43, 12, 0, 75, 433, 33, 76, 21, 5, 8, 320}
Dim query = From i In values WHERE i mod = 2 OrderBy i Select i

Or lets say you want to query some files on your computer.
Dim files = From file in GetFiles("c:\MyDirectory",".doc") OrderBy file.Name Select file

Or lets say you have a list of names in a List object, and you just want names that start with P
Dim Names = From x in MyList where x.StartsWith("P")  select x

The syntax is pretty SQLish, but as you can see it can be a real time saver when working with enumberables.
0
 
LVL 6

Assisted Solution

by:Allamz
Allamz earned 800 total points
ID: 23704155
Hello numberkruncher,

please note that Microsoft announced in a conference  that "LINQ To SQL" project will not be completed.

so i suggest u complete using SQL Command :)

BEst Regards,

Mohamed Allam
Senior Solution Developer
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 13

Author Comment

by:numberkruncher
ID: 23704805
Thanks for all of your input. I hadn't realized that Microsoft have given up on "LINQ to SQL".
0
 
LVL 13

Author Closing Comment

by:numberkruncher
ID: 31549674
Thanks all!
0
 
LVL 15

Expert Comment

by:aibusinesssolutions
ID: 23706120
@Allamz:  I'm not sure where you got your information, but MS is not dropping Linq to Sql, they will continue to update it, but they want people to start using the Entity Framework as soon as .NET Framework 4.0 comes out.  That being said, the EF "will be" the "preferred" method of connecting to SQL as of 4.0, they will continue to support Linq to SQL.

Here is a quote from the ADO.NET Blog

"Were making significant investments in the Entity Framework such that as of .NET 4.0 the Entity Framework will be our recommended data access solution for LINQ to relational scenarios.  We are listening to customers regarding LINQ to SQL and will continue to evolve the product based on feedback we receive from the community as well." - Tim Mallalieu, Program Manager, LINQ to SQL and Entity Framework
0
 
LVL 13

Author Comment

by:numberkruncher
ID: 23707026
That sounds interesting, I will take a further look into the new Entity Framework.
0
 
LVL 6

Expert Comment

by:Allamz
ID: 23707224
@aibusinesssolutions:

i've attended a training in Barcelona 2 months ago and i've met with the LINQ Team Leader and he told me that they won't proceed in the LINQ To SQL as they are developing a new framework and that doesn't mean that they'll cancel it. it'll be there with support but without new features, etc...

Regards,

Mohamed Allam
Senior Solution Developer
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how the fundamental information of how to create a table.
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question