ASP.NET - why to use linq

Asked By srikar
02-Dec-11 05:22 AM
why to use linq
  Suchit shah replied to srikar
02-Dec-11 05:29 AM
There are several reasons to why you would choose to use LINQ. First of let me clarify a common misconception when people first learn about LINQ. LINQ itself has nothing to do with SQL or databases.  There LINQ is an integrated query language for any collection; in fact anything that implements IENUMBERABLE. There is an added technology called LINQ to SQL which handles the connections to the database. I believe there are two main reasons why you would choose to use LINQ to SQL. First There are some very good performance improvements.   Because the expression tree is generated on the fly, this means that when updating the database only the fields that need to be sent to the db are. There are several good resources for this and to be honest this would be a whole day talking just about performance so I will point to Rico Mariani’s blog. Second is the code generation.  LINQ to SQL will generate object classes for you and provide you with partial classes and partial methods to extend this for business validation. This means there is not more tedious coding of properties etc. There is virtually unlimited customization here through there partial classes and methods as well as the ability to inherit. In short there are just so many options it is almost impossible to give you a simple answer to why you would use it. Also as with any technology there is times that you would not want to use it. I will point you to a slide deck that I have from a presentation I did a couple months ago along with some sample.http://utahdnug.org/files/folders/aug2007/entry151.aspx Please feel free to ping me back if you have any question. Also as a disclaimer I am by no means an expert on LINQ but I have been using it for quite some time and have experience implementing it in an enterprise environment.

The recommended Data Access Technology these days is the Entity Framework, not Linq To SQL or Typed Datasets. Just one of the reasons for the change is serialisation across boundaries. Typed Datasets include a whole load of clutter, whereas EF now produces POCO - Plain Old CLR Objects, which makes interoperability a lot easier. Another is the Code First approach - Typed Datasets require the database as a starting point. EF doesn't.

  Suchit shah replied to srikar
02-Dec-11 05:31 AM

http://www.dotnetfunda.com/interview/exam3825-what-are-the-advantages-of-linq-over-stored-procedures-.aspx

http://www.dotnetfunda.com/interview/exam3825-what-are-the-advantages-of-linq-over-stored-procedures-.aspx

Below is the three advantages of LINQ over stored procedures. 
 

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.

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.

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.

 

  R B replied to srikar
02-Dec-11 05:45 AM
HEllo

The popular answer is that LINQ is INtegrated with C# (or VB), thereby eliminating the impedance mismatch between programming languages and databases, as well as providing a single querying interface for a multitude of data sources. While that's true, it's only part of the story. More importantly: when it comes to querying databases, LINQ is in most cases a significantly more productive querying language than SQL.

  James H replied to srikar
02-Dec-11 06:04 AM
Check this Thread 
http://social.msdn.microsoft.com/forums/en-US/linqprojectgeneral/thread/45025b8a-90f6-40e1-87a8-45a1d496164f/

  James H replied to srikar
02-Dec-11 06:05 AM
Check this Thread 
http://social.msdn.microsoft.com/forums/en-US/linqprojectgeneral/thread/45025b8a-90f6-40e1-87a8-45a1d496164f/

  Riley K replied to srikar
02-Dec-11 07:24 AM
LINQ offers a great way to query database model where the whole logical model of the database is generated in the form of entities


You can also query on collections


Suppose to select all rows from table we use Select * from Emp


In LINQ we car assign the results to a Var type or List


  Var results=From n in dc.Employee
                        select n;



to query two tables, an example we can use is using the Northwind database.  Let's assume we want to join the Customers and Orders tables together

We would write a query like this to retrieve the OrderID, and OrderDate from the Order table, and the CustomerID and ContactName from the Customer table:

class Program
  {
  static void Main(string[] args)
  {
  using (DataClasses1DataContext db = new DataClasses1DataContext())
  {
 
 
  var query_results = from d in db.Customers
      join o in db.Orders
      on d.CustomerID equals o.CustomerID
      select new { o.OrderID, o.OrderDate, d.CustomerID, d.ContactName };
    
 
 
  }
  }
   
 
 
}



 You can refer 101 LINQ samples
http:///

Regards
  Reena Jain replied to srikar
02-Dec-11 07:30 AM
HI,

LINQ offers a great way to query database model where the whole logical model of the database is generated in the form of entities
You can also query on collections
Suppose to select all rows from table we use Select * from Emp


In LINQ we car assign the results to a Var type or List


  Var results=From n in dc.Employee
                        select n;



to query two tables, an example we can use is using the Northwind database.  Let's assume we want to join the Customers and Orders tables together

We would write a query like this to retrieve the OrderID, and OrderDate from the Order table, and the CustomerID and ContactName from the Customer table:

class Program
  {
  static void Main(string[] args)
  {
    using (DataClasses1DataContext db = new DataClasses1DataContext())
    {
 
 
    var query_results = from d in db.Customers
          join o in db.Orders
          on d.CustomerID equals o.CustomerID
          select new { o.OrderID, o.OrderDate, d.CustomerID, d.ContactName };
      
 
 
    }
  }
   
 
 
}


 You can refer 101 LINQ samples
Create New Account
help
Net hi friends Any one send frequently asked Important questions in C# .Net, ADO .Net, Asp .Net and Sql Server. . . . . . . . tx in Advance. . . . . . Hi, Find this. . (B)What is an IL? (B How can we know a state of a thread? (A) What is use of Interlocked class ? (A) What is a monitor object? (A) What are wait handles? (A) What is ManualResetEvent and Webservices (B)What is an application domain? (B) What is .NET Remoting? (B) Which class does the remote object has to inherit? (I) what are two different types of remote A) What is scavenging? (B) What are different types of caching using cache object of ASP.NET? (B) How can you cache different version of same page using ASP.NET cache object? (A) How will implement Page Fragment Caching? (B) Can you compare ASP.NET
LINQ Hi to All, please tell me about linq. . .? advantage. . . HEllo LINQ may be used to access all types of data, whereas embedded SQL is limited to addressing only databases that can handle SQL queries. Below are the advantages and Disadvantages of LINQ Advantages : • It is a cleaner and typesafety. • It is checked by the compiler instead of not just tables in a relational database but also text files and XML files. Disadvantages: • LINQ sends the entire query to the DB hence takes much network traffic but the stored if the queries are very complex. • Preformance is degraded if we don't write the linq query correctly. • If you need to make changes to the way you do data access, you need to recompile, version, and redeploy your assembly. Hello Some advantages of LINQ over sprocs: • Type safety : I think we all understand this. • Abstraction : This is especially true with LINQ-to-Entities . This abstraction also allows the framework to add additional improvements that you can
how i can create simple insert update using linq in asp.net Hi all how i can create simple insert update delete application using linq in asp.net please help me step by step thanks regards LINQ itself doesn't do database "insert update and delete". You can use LINQ to SQL or Entity Framework to model and connect to your database, and LINQ to
Can anybody tells me that what is MVC and what the use of MVC in ASP.net. . I have seen lot of links but couldn't get in easy way. . Also tell me that how to learn MVC ASP.NET MVC is a part of the ASP.NET Web application framework. It is one of the two different programming models you can use to create ASP.NET Web applications, the other being ASP.NET Web Forms. An MVC Application is designed
Distributed Data Grids - Share Objects Between Windows Service and ASP.NET I've included a sample that demonstrates how to share in memory objects from their server store between windows services, windows forms, wcf, and asp.net applications using ScaleOut StateServer. It is much simpler to implement than named pipes and incredibly d ata grids . To make a simplistic analogy, it is a little like having an ASP.NET Application Cache that is replicated across any server, anywhere on your network, that is running a SOSS instance on it. Just like in ASP.NET, you give the cache item a name and shove objects in it. However, unlike ASP