LINQ - practical example - Asked By goldy gupta on 15-Nov-11 06:35 AM

Can anybody give a example of
these lines

as i am not getting the highlighted parts

There are couple of advantage of LINQ over stored procedures. 

1. Debugging - It is really very hard to debug the Stored procedure but as LINQ is part of .NET, you can use visual studio's debugger to debug the queries. 

2. Deployment - With stored procedures, we need to provide an additional script for stored procedures but with LINQ everything gets complied into single DLL hence deployment becomes easy. 

3. Type Safety - LINQ is type safe, so queries errors are type checked at compile time. It is really good to encounter an error when compiling rather than runtime exception!
Suchit shah replied to goldy gupta on 15-Nov-11 06:49 AM

Debugging - As debug point concern, as LINQ is part of .NET, we can use the visual studio's debugger to debug the queries but it is tough to debug the Stored procedure as it will not support the visual studio debugger.

So here for Debugging if we create a SP then we can not able to Debugging same way which we are doing on visual studio for other code but we can able to debug the LINQ query


Deployment - In case of deployment, we need to provide an additional script for stored procedures to execute but in case of LINQ, it will complie into single DLL hence deployment becomes easier.

When you compile the code at that time for each and every LINQ query single dll file has been created while there are different file for each and every SP


Type Safety - As LINQ is type safe, the queries errors are type checked at compile time. Better suggest to use LINQ because it helps to encounter an error at the compile time rather than at runtime exception.


As you know, LINQ to SQL is an ORM tool in .NET to improve your productivity. All the LINQ queries will be converted into SQL queries finally. Based on my expirence, it depends on you to use which way. It may be more complex when you write a stored procedure, but it may be easier and safer(type check when compiling) to implement it in LINQ queries. But a stored procedure is precompiled in database, and can run faster than general SQL queries. As a brief conclusion, if you want to run the query in the fastest way, you can choose stored procedure. But if you want to build your application in a shorter time with less code, you can choose LINQ to SQL.


Hope it helps...

 

Web Star replied to goldy gupta on 15-Nov-11 06:50 AM
Ans 1. Actually debug in Strored proc is deficult in Sql server where as LINQ query written in .cs file so it will debug very easily in Visual studio's debugger help of break point immediate window quick view etc

Ans 2. Deployment is very easily because code written in  class file in .net so it will build in single DLL when build your application in VS.

Ans 3. LINQ is type safe because type checking at compile time.

goldy gupta replied to Suchit shah on 15-Nov-11 06:55 AM
I get all the points suchit but except First point

what is visual studio debugger. .Is this a simple debug by hitting F5 or what.
Suppose i make a breakpoint in my linq query so how i see result under that breakpoint
Chintan Vaghela replied to goldy gupta on 15-Nov-11 06:58 AM
Hello,

1. Debugging - It is really very hard to debug the Stored procedure but as LINQ is part of .NET, you can use visual studio's debugger to debug the queries. 

-  Debug code using Visual Studio (Press F5 and break point to your code Press F9)

2. Deployment - With stored procedures, we need to provide an additional script for stored procedures but with LINQ everything gets complied into single DLL hence deployment becomes easy. 

- All Linq Class merge in Single DLL. So diploy easily
3. Type Safety - LINQ is type safe, so queries errors are type checked at compile time. It is really good to encounter an error when compiling rather than runtime exception!

- It means if int datatype assign string then display error at complile time (Press Ctrl+Shift+B)

Suchit shah replied to goldy gupta on 15-Nov-11 07:03 AM

The Visual Studio 2010 debugger has been enhanced by the  following features:

  • Breakpoint enhancements, which include the ability to search in the Breakpoints window, the ability to label breakpoints, the ability to import and export breakpoints, and string comparison for breakpoint conditions in native debugging.

  • WPF debugging enhancements,

  • A newly redesigned Threads window provides filtering, call-stack searching and expansion, and grouping. New columns display affinity masks, process names, and managed IDs. You can customize which columns appear and in what order.

  • You can use the Parallel Stacks and Parallel Tasks debugger tool windows to visualize and debug parallel code that is written in C++, C#, or Visual Basic.

  • Enhanced DataTips can float on top of other windows or be pinned.

  • For dump debugging, a new summary page displays basic information about the contents of the dump file before you start to debug.

  • The Watch window and DataTips provide an icon to warn you when an evaluating an expression requires other threads to run,

  • Enhancements to symbol loading.

  • You can now debug mixed-mode native and managed code on 64-bit operating systems.


    So Your concept is right Debugging means u can put the Break Point and check your code step by step and you can able to see the value of any variable or result of the LINQ query on the same way which we are doing for the other ASP.Net control for e.g. say you are debugging your code and if u want to see after some point of time that what is the value of Txtname.Text now so what you can do same thing here you can do it for LINQ query to see the result set.



goldy gupta replied to Suchit shah on 15-Nov-11 07:12 AM
Thats I got again thanks so much suchit.
goldy gupta replied to Chintan Vaghela on 15-Nov-11 07:17 AM
Thanks
Suchit shah replied to goldy gupta on 15-Nov-11 07:40 AM
You are most welcom :)
Chintan Vaghela replied to goldy gupta on 15-Nov-11 07:49 AM
welcome