Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Language Integrated Query By Nyros Developer

1,502 views

Published on

Language Integrated Query By Nyros Developer

  • Be the first to comment

  • Be the first to like this

Language Integrated Query By Nyros Developer

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

×