Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why and When to use LINQ? [closed]

i have never used LINQ in any of my projects , i have always used ado.net /OR tool in my Business App projects , so i want to know What are the benefits of LINQ ? why and when anybody should use LINQ ?

like image 271
Adeel Avatar asked Dec 04 '08 05:12

Adeel


People also ask

When should you use LINQ?

Readable code: LINQ makes the code more readable so other developers can easily understand and maintain it. Standardized way of querying multiple data sources: The same LINQ syntax can be used to query multiple data sources. Compile time safety of queries: It provides type checking of objects at compile time.

What are the advantages of using LINQ?

Advantages of Using LINQLINQ offers a common syntax for querying any type of data sources. Secondly, it binds the gap between relational and object-oriented approachs. LINQ expedites development time by catching errors at compile time and includes IntelliSense & Debugging support. LINQ expressions are Strongly Typed.

What is LINQ and why use it?

Language-Integrated Query (LINQ) is the name for a set of technologies based on the integration of query capabilities directly into the C# language. Traditionally, queries against data are expressed as simple strings without type checking at compile time or IntelliSense support.

Why we use LINQ instead of SQL?

More importantly: when it comes to querying databases, LINQ is in most cases a significantly more productive querying language than SQL. Compared to SQL, LINQ is simpler, tidier, and higher-level. It's rather like comparing C# to C++.


2 Answers

Just to clarify there are differences between the concept of LINQ and LINQ to SQL.

LINQ is a query syntax, not a language or an O/RM. You can build an O/RM on top of the syntax provided by LINQ.

Since I gather that your question is really When to use LINQ to SQL I'll just address that.

LINQ to SQL is best used when you are:

  • Only ever targeting MS SQL 2000+
  • Doing RAD

I've used LINQ to SQL on a couple of commercial products and quite a few of my own products and found these benefits:

  • Familiar language to code in (C#/ VB.NET)
  • Easier to maintain (we have more .NET than SQL gurus on staff)
  • SQL generated is well structured and very optimal
  • Allows direct translation of business rules to SQL while still keeping all business logic in a single project

As for LINQ as a concept I use it all the time, because I understand what it can/can't do and how to use it properly. Like any language feature it can be miss-used easily if people don't have an understanding of what it is and how to use it. I recommend the following blogs to get some of the concepts of LINQ down:

  • Bart De Smet - advanced
  • Charlie Calvert
  • Wriju
like image 90
Aaron Powell Avatar answered Oct 25 '22 10:10

Aaron Powell


This is a fair question but has been asked many times already. See these earlier questions for a more in depth and broader coverage:

All about Linq

Beginners guide to Linq

What's the hardest or most misunderstood aspect of Linq

like image 26
Ash Avatar answered Oct 25 '22 11:10

Ash