Language Integrated Query By Nyros Developer

  • 1,179 views
Uploaded on

Language Integrated Query By Nyros Developer

Language Integrated Query By Nyros Developer

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
1,179
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
41
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1.
    • WELCOME TO ALL
  • 2. LINQ
    • Language Integrated Query provides built - in language querying functionality similar to SQL.
    • LINQ defines a set of standard query operators in the System.Linq namespace to select, filter, aggregate, and partition data.
    • LINQ is a new feature in Visual Studio 2008 and the .NET Framework 3.5
  • 3. Components in LINQ
    • System.Linq C ontains the set of standard query operators and types and interfaces.
    • System.Data.Linq Contains classes that support interaction with relation data base.
    • System.Xml.Linq Contains classes for LINQ to XML
  • 4. Operators in LINQ
    • Average
    • Cast
    • ElementAt
    • ElementAtOrDefault
    • First
    • FirstOrDefault
    • Last
    • Reverse
    • Skip
    • SkipWhile
  • 5. Example on Operators
    • int[] nums = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024 };
    • int num1 = nums.First<int>();
    • int num2 = nums.First<int>(x => x > 50);
    • int num3 = nums.FirstOrDefault<int>(x => x > 5000);
    • Console.WriteLine(
    • num1.ToString() + &quot;-&quot; +
    • num2.ToString() + &quot;-&quot; +
    • num3.ToString());
  • 6. LINQ Provider
    • It is a gate for LINQ to act up on data that is not inside a queryable type.
    • 1)Linq to Objects
    • 2)Linq to XML
    • 3)Linq to SQL
    • 4)Linq to Datasets
  • 7. LINQ to Objects
    • string [] country = { &quot;India&quot; , &quot;China&quot; , &quot;America&quot; , &quot;Nepal&quot; }; IEnumerable < string > query =   from n in country                              where n.Length == 5                              orderby n descending                              select n; foreach ( string name in query)
    • {
    • Response.Write(name.ToString());
    • }           
  • 8. LINQ to XML
    • XElement countries = XElement .Parse(                @&quot;<countries>                    <country> India </country>                    <country> China </country>                    <country> America </country>                  </countries>&quot;             ); IEnumerable < string > query = from n in countries .Elements( &quot;country&quot; )                              where n.Value.Length == 5                              orderby n.Value descending                              select n.Value;
  • 9. LINQ to SQL
    • It allows .NET developers to write &quot;queries&quot; in their .NET language of choice.
    • The LINQ to SQL provider allows LINQ to be used to query SQL Server databases as well as Sql server compact database.
    • It has better support for server oriented features.
    • It is less complicated.
    • It has some what better performance.
  • 10.
    • SELECT ContactId, FirstName,LastName,DateOfBirth,Phone,Emai l
    • FROM [ Contact ]
    • WHERE DATEADD ( YEAR, @p0, DateOfBirth ) > @p1
    • ORDER BY DateOfBirth DESC
    • DataContext db = new DataContext ( &quot;&quot; );
    • var q = from c in db. Contact
    • where c. DateOfBirth . AddYears ( 35 ) > DateTime. Now
    • orderby c. DateOfBirth descending
    • select c;
  • 11. LINQ on DataSets
    • The DataSet is an in-memory representation of relational data
    • SqlDataAdapter da = new SqlDataAdapter(
    • &quot;SELECT * FROM Customers&quot;,
    • _connectionString);
    • DataTable customers = new DataTable(&quot;customers&quot;);
    • da.Fill(customers);
    • int countOfCustomers =
    • (from c in customers.AsEnumerable()
    • where c.Field<string>(&quot;Country&quot;) == &quot;France&quot;
    • select c).Count();
  • 12. Conclusion
    • We can work on diverse data bases like Objects,SQL,DataSets....
    • Provides consistency by defining a set of standard query operators
    • Deeply integrated into .Net languages
    • Intellisense for auto-completion
    • Performance is high
    • Compiler can perform syntax and type checking on query expressions
    • It is very powerful all on its own.
  • 13.
    • THANK YOU