LINQ - Linq query - Asked By s j on 21-Nov-11 06:39 AM



Hi
I'm working for asp.net application,where i have to implement MVC architecture. For this i have to use LINQ. But i'm new to work on this. And im totally got confused with this.

Plzz explain me about which topics do i need to learn in LINQ  and also explain simple quries .



Cheers,
Samantha.
Suchit shah replied to s j on 21-Nov-11 06:48 AM
What are the four LINQ Providers that .NET Framework ships?
1. LINQ to Objects - Executes a LINQ query against a collection of objects
2. LINQ to XML - Executes an XPATH query against XML documents
3. LINQ to SQL - Executes LINQ queries against Microsoft SQL Server.
4. LINQ to DataSets - Executes LINQ queries against ADO.NET DataSets.

The main LINQ concept you get it from
http://www.codeproject.com/KB/linq/IntroducingLINQ.aspx
http://www.codeproject.com/KB/linq/LINQtoSQLBasic.aspx
http://www.codeproject.com/KB/linq/LINQtoSQLAdvanced.aspx
http://www.asp.net/linq/videos ( Here you get the List of Video for the LINQ)
http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx

http://msdn.microsoft.com/en-us/library/bb386913.aspx

List of all very good LINQ Videos ( http://www.asp.net/linq/videos)
LINQ Query Samples (
http://msdn.microsoft.com/en-us/vstudio/bb688084.aspx)
LINQ to SQL for the Beginner(http://www.codeproject.com/KB/linq/Entity_Classes.aspx)
A LINQ Tutorial: Adding/Updating/Deleting Data(http://www.codeproject.com/KB/linq/linqtutorial2.aspx)
A LINQ Tutorial: WPF Data Binding with LINQ to SQL(http://www.codeproject.com/KB/linq/linqtutorial3.aspx)


Here are Link to download all LINQ samples (http://msdn.microsoft.com/en-us/vstudio/bb688088)
Anil Kumar replied to s j on 21-Nov-11 07:22 AM
Hi Samantha,

Microsoft has come up with a general-purpose query facilities to the .NET Framework that apply to all sources of information, not just relational or XML data. This facility is called .NET Language-Integrated Query (LINQ).

We use the term language-integrated query to indicate that query is an integrated feature of the developer's primary programming languages (for example, Visual C#, Visual Basic). Language-integrated query allows query expressions to benefit from the rich metadata, compile-time syntax checking, static typing and IntelliSense that was previously available only to imperative code. Language-integrated query also allows a single general purpose declarative query facility to be applied to all in-memory information, not just information from external sources.

.NET Language-Integrated Query defines a set of general purpose standard query operators that allow traversal, filter, and projection operations to be expressed in a direct yet declarative way in any .NET-based programming language. The standard query operators allow queries to be applied to any IEnumerable<T>-based information source. LINQ allows third parties to augment the set of standard query operators with new domain-specific operators that are appropriate for the target domain or technology. More importantly, third parties are also free to replace the standard query operators with their own implementations that provide additional services such as remote evaluation, query translation, optimization, and so on. By adhering to the conventions of the LINQ pattern, such implementations enjoy the same language integration and tool support as the standard query operators.

The extensibility of the query architecture is used in the LINQ project itself to provide implementations that work over both XML and SQL data. The query operators over XML (LINQ to XML) use an efficient, easy-to-use, in-memory XML facility to provide XPath/XQuery functionality in the host programming language. The query operators over relational data (LINQ to SQL) build on the integration of SQL-based schema definitions into the common language runtime (CLR) type system. This integration provides strong typing over relational data while retaining the expressive power of the relational model and the performance of query evaluation directly in the underlying store.


Example code:

using System;
using System.Linq;
using System.Collections.Generic;
class app {
  static void Main() {
    string[] names = { "Burke", "Connor", "Frank", 
                       "Everett", "Albert", "George", 
                       "Harris", "David" };
    IEnumerable<string> query = from s in names 
                               where s.Length == 5
                               orderby s
                               select s.ToUpper();
    foreach (string item in query)
      Console.WriteLine(item);
  }
}

After compilation:

BURKE
DAVID
FRANK
To understand how language-integrated query works, we need to dissect the
 first statement of our program.
IEnumerable<string> query = from s in names 
                           where s.Length == 5
                           orderby s
                           select s.ToUpper();

Hope it helps you.
Thank you
Anil
Reena Jain replied to s j on 21-Nov-11 07:22 AM
hi,

LINQ is a set of extensions to the .NET Framework that encompass language-integrated query, set, and transform operations. It extends C# and Visual Basic with native language syntax for queries and provides class libraries to take advantage of these capabilities.

Featured Information


Essential LINQ (Microsoft .NET Development Series)

LINQ is one of Microsoft’s most exciting, powerful new development technologies.Essential LINQ is the first LINQ book written by leading members of Microsoft’s LINQ and C# teams.

LINQ to XML
LINQ to XML was developed with Language-Integrated Query over XML in mind and takes advantage of standard query operators and adds query extensions specific to XML.

Follow these googd links-

http://msdn.microsoft.com/en-us/netframework/aa904594
http://msdn.microsoft.com/en-us/library/bb308959.aspx

Hope this will help you.

Riley K replied to s j on 21-Nov-11 08:45 PM




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


Regards
 




s j replied to Riley K on 24-Nov-11 12:05 AM


Hi  Riley.
Thank you for your post. Can you plz give me the link for 101  linq samples.



Cheers,
Samantha.
Riley K replied to s j on 24-Nov-11 01:48 AM

Hi Samantha,

Here is the link

http://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b

Download and practice them


Regards