SlideShare a Scribd company logo
1 of 42
LINQ  By  PranayRana Blog : http://pranayamr.blogspot.com Twitter : http://twitter.com/pranayamr FaceBook : http://www.facebook.com/pages/GMind-Solution
Overview Implicitly typed local variables  Anonymous Types Object and Collection Initialization Extension Method Lambda Expression Linq
Virtual Diagram LINQ Anonymos Types Implicitly typed local variables   Extension   Method Object and Collection Initialization Lambda Expression
Implicitly typed local variables ,[object Object],var i = 5; var s = "Hello"; var d = 1.0; var numbers = new int[] {1, 2, 3}; var orders = new  ,[object Object]
No need to define type ,[object Object]
var x; // Error, no initializer to infer type from var y = {1, 2, 3}; // Error, collection initializer not permitted var z = null; // Error, null type not permitted
Anonymous Types What is Anonymous types ? Create new types without defining it How to define Anonymous types ? var pranay = new { id=1, Name= "pranay rana" }; var krunal = new { id=1, Name= "krunal mevada" }; Use of it var user = from user in Users   select new { user.Name, user.Id};
Object and Collection Initialization What is object Initialization ? create object without writing too much lengthy code and without invoking constructor. Example class Employee {   public string Name { get; set; }   public string Address { get; set; }    public Employee(){}  public Employee (string name) { Name= name;  } }
Employee emp = new Employee() { Name="Pranay", Address="Ahmedabad"  }; or Employee emp = new Employee("Hemang") { Address="Ahmedabad"   };
Collection Initialization List<Employee> emp = new List<Employee>       {          new Employee { Name="Pranay",                                           Address="Ahmedabad"  },          new Employee { Name="Krunal", Address="Mevada"  },          null      };
Extension Method What is Extesion Methods ? Allow programmer to "add" methods to existing types without creating a new derived type, recompiling, or by modifying the original type Example public static class Utilities {     public static string encryptString(this string str)     {            System.Security.Cryptography.MD5CryptoServiceProvider x =                          new      System.Security.Cryptography.MD5CryptoServiceProvider();            byte[] data = System.Text.Encoding.ASCII.GetBytes(str);            data = x.ComputeHash(data);            return System.Text.Encoding.ASCII.GetString(data);      } }
Lambda Expression Replacement of the anonymous method available in C#2.0 Consist of single line or block of statement => is lamda expression operator Syntax ( param ) => expr(int x) = > { return x + 1 }; param => exprx=> x + 1;
Use of Lambda expression C#2.0 by using anonymous method     List<int> even =         lstNumber.FindAll( delegate(inti) { if(i%2==)                                                                    return i; } But for the C#3.0 with the lambda expression it will       List<int> even            = lstNumber.FindAll( i => (i%2) ==0 } In LINQ var order = orders.where( o=> o.ProcessStatus  =  ProcessStatus.Completed);
What is orm ? Object Relational Mapping  Allow to map your database structure with the business layer model  Hide low level database interaction details Make development easy and faster
LINQ What is LINQ ? Language-Integrated Query  Made up to make query any source of data Some flavor of LINQ LINQ to Object {Queries performed against the in-memory data} LINQ to SQL (formerly DLinq) {Queries performed against the relation database only Microsoft SQL Server Supported} LINQ to DataSet {Supports queries by using ADO.NET data sets and data tables} LINQ to Entities {Microsoft ORM solution} LINQ to XML (formerly XLinq) { Queries performed against the XML source}
Select SQL SELECT * FROM [User] ,[object Object]
var user = from u in Users select u;,[object Object]
Select with Columns SQL  Select FirstName, LastName from [User] ,[object Object],from u in Users  select new  { u.FirstName, u.LastName };
Filter Selected Data SQL Select firstname,LastName from [User] where id = 3 ,[object Object],from u in Users  where u.Id ==3 select new  { u.FirstName, u.LastName };
Filtering String Data SQL SELECT [Id], [FirstName], [LastName], [Email], [DisplayName], [Address1], [Address2], [Password], [Role] FROM [User] WHERE [Email] LIKE '%pranay%' ,[object Object],    from u in Users where u.Email.Contains ("pranay") select u; Or     from u in Users where u.Email.StartsWith ("pranay") select u;
Inner Join SQL SELECT [User].[Id], [FirstName], [LastName], [UserId], [MobileNo] FROM [User] INNER JOIN [UserClients] ON [User].[id] = [UserId] ,[object Object],var user = from u in Users      join uc in UserClients on u.Id equals uc.UserId select new      {  u.Id, u.FirstName, u.LastName, uc.MobileNo,    uc.imeiNO, uc.Id,      };
Outer Join SQL SELECT [t0].[Id], [FirstName], [LastName], [UserId] AS [UserId], [MobileNo] AS [MobileNo] FROM [User] AS [t0] LEFT OUTER JOIN [UserClients] ON ([t0].[id]) = [UserId] ,[object Object],var user = from u in Users  join uc in UserClients on u.Id equals uc.UserId into myuserwithclient from m in myuserwithclient.DefaultIfEmpty()  select new  { u.Id, u.FirstName, u.LastName, m.UserId, m.MobileNo };
Ordering Data SQL Select * from [User] order by firstName ,[object Object],var user = from u in Users orderbyu.FirstName select new     { u.FirstName, u.LastName }; ,[object Object],varemp = from e in dc.Employeesorderbye.Name, e.Desc select e;
Grouping Data SQL SELECT COUNT(*) AS [test], [UserId] FROM [UserClients] GROUP BY [UserId] ,[object Object],var user = from u in UserClients   group u by u.UserId    into c    select new     { t1 = c.Key, tcount = c.Count() };
Filter Data Using IN and NOT IN Clauses SQL SELECT [Id], [UserId], [IMEINo] FROM [UserClients] WHERE [UserId] IN (3, 4) ,[object Object],int[] chosenOnes = { 3, 4 }; var user = from u in UserClients              where chosenOnes.Contains(u.UserId.Value)               select new                { u.id,u.userid, u.ImeiNo};
Filtering Data by Row Numbers SQL SELECT * FROM ( SELECT ROW_NUMBER() OVER (ORDER BY [id]) AS [ROW_NUMBER], [id], [FirstName], [LastName], [Email], [DisplayName], [Address1], [Address2], [Password], [Role] FROM [User] AS [t0] ) AS [t1] WHERE [t1].[ROW_NUMBER]  BETWEEN 11 AND 20  ORDER BY [t1].[ROW_NUMBER] ,[object Object],var users = from u in Users select u;  varfilterUsers=  users.OrderBy (p => p.Id).Skip (10).Take(10);
SQL ISNULL function LINQ var user = from u in Users join uc in UserClients on u.Id equals uc.UserId into myuserwithclient from m in myuserwithclient.DefaultIfEmpty() select new  {  u.Id,  FirstName= u.FirstName,  LastName= u.LastName,  UserId= m.UserId,  MobileNo= m.MobileNo?? "N/A"  };
Selectmany Flattens the resulting sequences into one sequence users.SelectMany (       u => u.Userclient,        (u, uc) =>           new           {             Name = u.Name,              Mobileno = uc.Mobile,              IsApproved = uc.IsApproved          }    )
Linq Deferred Execution Query not going to execute at this point    var query =         from customer in db.Customers where   customer.City == "Paris" select customer;  Query get executed when we apply method like (Count(),toList() etc.) int count =    (from customer in db.Customers where   customer.City == "Paris" select customer).Count();
Questions  and  Query
Thank YOU

More Related Content

What's hot

11. session 11 functions and objects
11. session 11   functions and objects11. session 11   functions and objects
11. session 11 functions and objectsPhúc Đỗ
 
Object oriented programming using c++
Object oriented programming using c++Object oriented programming using c++
Object oriented programming using c++Hoang Nguyen
 
Pattern Matching - at a glance
Pattern Matching - at a glancePattern Matching - at a glance
Pattern Matching - at a glanceKnoldus Inc.
 
Object oriented programming in C++
Object oriented programming in C++Object oriented programming in C++
Object oriented programming in C++jehan1987
 
NLJUG University Sessie: Java Reborn, Powered by Ordina
NLJUG University Sessie: Java Reborn, Powered by OrdinaNLJUG University Sessie: Java Reborn, Powered by Ordina
NLJUG University Sessie: Java Reborn, Powered by OrdinaMartijn Blankestijn
 
How to extract domain name from email address
How to extract domain name from email addressHow to extract domain name from email address
How to extract domain name from email addressHenley Walls
 
XML & XPath Injections
XML & XPath InjectionsXML & XPath Injections
XML & XPath InjectionsAMol NAik
 
Breaking down data silos with the open data protocol
Breaking down data silos with the open data protocolBreaking down data silos with the open data protocol
Breaking down data silos with the open data protocolWoodruff Solutions LLC
 
JavaScript - Chapter 10 - Strings and Arrays
 JavaScript - Chapter 10 - Strings and Arrays JavaScript - Chapter 10 - Strings and Arrays
JavaScript - Chapter 10 - Strings and ArraysWebStackAcademy
 
Chapter 2 - Getting Started with Java
Chapter 2 - Getting Started with JavaChapter 2 - Getting Started with Java
Chapter 2 - Getting Started with JavaEduardo Bergavera
 
Java Foundations: Methods
Java Foundations: MethodsJava Foundations: Methods
Java Foundations: MethodsSvetlin Nakov
 
Types in JavaScript: why you should care
Types in JavaScript: why you should careTypes in JavaScript: why you should care
Types in JavaScript: why you should careJean Carlo Emer
 
Core java by a introduction sandesh sharma
Core java by a introduction sandesh sharmaCore java by a introduction sandesh sharma
Core java by a introduction sandesh sharmaSandesh Sharma
 

What's hot (20)

Python dictionary
Python   dictionaryPython   dictionary
Python dictionary
 
11. session 11 functions and objects
11. session 11   functions and objects11. session 11   functions and objects
11. session 11 functions and objects
 
Introduction to c ++ part -2
Introduction to c ++   part -2Introduction to c ++   part -2
Introduction to c ++ part -2
 
Object oriented programming using c++
Object oriented programming using c++Object oriented programming using c++
Object oriented programming using c++
 
Functional Programming with C#
Functional Programming with C#Functional Programming with C#
Functional Programming with C#
 
Pattern Matching - at a glance
Pattern Matching - at a glancePattern Matching - at a glance
Pattern Matching - at a glance
 
C++ oop
C++ oopC++ oop
C++ oop
 
Object oriented programming in C++
Object oriented programming in C++Object oriented programming in C++
Object oriented programming in C++
 
XPath Injection
XPath InjectionXPath Injection
XPath Injection
 
NLJUG University Sessie: Java Reborn, Powered by Ordina
NLJUG University Sessie: Java Reborn, Powered by OrdinaNLJUG University Sessie: Java Reborn, Powered by Ordina
NLJUG University Sessie: Java Reborn, Powered by Ordina
 
How to extract domain name from email address
How to extract domain name from email addressHow to extract domain name from email address
How to extract domain name from email address
 
XML & XPath Injections
XML & XPath InjectionsXML & XPath Injections
XML & XPath Injections
 
Breaking down data silos with the open data protocol
Breaking down data silos with the open data protocolBreaking down data silos with the open data protocol
Breaking down data silos with the open data protocol
 
Hacking XPATH 2.0
Hacking XPATH 2.0Hacking XPATH 2.0
Hacking XPATH 2.0
 
JavaScript - Chapter 10 - Strings and Arrays
 JavaScript - Chapter 10 - Strings and Arrays JavaScript - Chapter 10 - Strings and Arrays
JavaScript - Chapter 10 - Strings and Arrays
 
Chapter 16 Dictionaries
Chapter 16 DictionariesChapter 16 Dictionaries
Chapter 16 Dictionaries
 
Chapter 2 - Getting Started with Java
Chapter 2 - Getting Started with JavaChapter 2 - Getting Started with Java
Chapter 2 - Getting Started with Java
 
Java Foundations: Methods
Java Foundations: MethodsJava Foundations: Methods
Java Foundations: Methods
 
Types in JavaScript: why you should care
Types in JavaScript: why you should careTypes in JavaScript: why you should care
Types in JavaScript: why you should care
 
Core java by a introduction sandesh sharma
Core java by a introduction sandesh sharmaCore java by a introduction sandesh sharma
Core java by a introduction sandesh sharma
 

Viewers also liked

Linq to entity
Linq to entityLinq to entity
Linq to entitybuianhtai
 
Ling to SQL and Entity Framework performance analysis
Ling to SQL and Entity Framework performance analysisLing to SQL and Entity Framework performance analysis
Ling to SQL and Entity Framework performance analysisAlexander Konduforov
 
20130329 introduction to linq
20130329 introduction to linq20130329 introduction to linq
20130329 introduction to linqLearningTech
 
Entity Framework - Queries
Entity Framework -  QueriesEntity Framework -  Queries
Entity Framework - QueriesEyal Vardi
 
Entity framework
Entity frameworkEntity framework
Entity frameworkicubesystem
 
Entity Framework - Entity Data Model (edm)
Entity Framework - Entity Data Model (edm)Entity Framework - Entity Data Model (edm)
Entity Framework - Entity Data Model (edm)Eyal Vardi
 
メタプログラミング C#
メタプログラミング C#メタプログラミング C#
メタプログラミング C#Fujio Kojima
 
C# 式木 (Expression Tree) ~ LINQをより深く理解するために ~
C# 式木 (Expression Tree) ~ LINQをより深く理解するために ~C# 式木 (Expression Tree) ~ LINQをより深く理解するために ~
C# 式木 (Expression Tree) ~ LINQをより深く理解するために ~Fujio Kojima
 
LINQ 2 SQL Presentation To Palmchip And Trg, Technology Resource Group
LINQ 2 SQL Presentation To Palmchip  And Trg, Technology Resource GroupLINQ 2 SQL Presentation To Palmchip  And Trg, Technology Resource Group
LINQ 2 SQL Presentation To Palmchip And Trg, Technology Resource GroupShahzad
 

Viewers also liked (20)

Linq to entity
Linq to entityLinq to entity
Linq to entity
 
Linq e Ef
Linq e EfLinq e Ef
Linq e Ef
 
LINQ for absolute beginners
LINQ for absolute beginnersLINQ for absolute beginners
LINQ for absolute beginners
 
Ling to SQL and Entity Framework performance analysis
Ling to SQL and Entity Framework performance analysisLing to SQL and Entity Framework performance analysis
Ling to SQL and Entity Framework performance analysis
 
B_110500002
B_110500002B_110500002
B_110500002
 
20130329 introduction to linq
20130329 introduction to linq20130329 introduction to linq
20130329 introduction to linq
 
Linq intro
Linq introLinq intro
Linq intro
 
Entity Framework - Queries
Entity Framework -  QueriesEntity Framework -  Queries
Entity Framework - Queries
 
Entity framework
Entity frameworkEntity framework
Entity framework
 
LINQ
LINQLINQ
LINQ
 
The Entity Data Model
The Entity Data ModelThe Entity Data Model
The Entity Data Model
 
Entity Framework - Entity Data Model (edm)
Entity Framework - Entity Data Model (edm)Entity Framework - Entity Data Model (edm)
Entity Framework - Entity Data Model (edm)
 
LINQ and LINQPad
LINQ and LINQPadLINQ and LINQPad
LINQ and LINQPad
 
Think in linq
Think in linqThink in linq
Think in linq
 
PostCss
PostCssPostCss
PostCss
 
メタプログラミング C#
メタプログラミング C#メタプログラミング C#
メタプログラミング C#
 
C# 式木 (Expression Tree) ~ LINQをより深く理解するために ~
C# 式木 (Expression Tree) ~ LINQをより深く理解するために ~C# 式木 (Expression Tree) ~ LINQをより深く理解するために ~
C# 式木 (Expression Tree) ~ LINQをより深く理解するために ~
 
LINQ in C#
LINQ in C#LINQ in C#
LINQ in C#
 
LINQ 2 SQL Presentation To Palmchip And Trg, Technology Resource Group
LINQ 2 SQL Presentation To Palmchip  And Trg, Technology Resource GroupLINQ 2 SQL Presentation To Palmchip  And Trg, Technology Resource Group
LINQ 2 SQL Presentation To Palmchip And Trg, Technology Resource Group
 
Linq
LinqLinq
Linq
 

Similar to Linq

Language Integrated Query By Nyros Developer
Language Integrated Query By Nyros DeveloperLanguage Integrated Query By Nyros Developer
Language Integrated Query By Nyros DeveloperNyros Technologies
 
Embedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for JavaEmbedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for JavaJevgeni Kabanov
 
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05CHOOSE
 
Python Programming by Dr. C. Sreedhar.pdf
Python Programming by Dr. C. Sreedhar.pdfPython Programming by Dr. C. Sreedhar.pdf
Python Programming by Dr. C. Sreedhar.pdfSreedhar Chowdam
 
Linq in C# 3.0: An Overview
Linq in C# 3.0: An OverviewLinq in C# 3.0: An Overview
Linq in C# 3.0: An Overviewpradeepkothiyal
 
C++ Course - Lesson 3
C++ Course - Lesson 3C++ Course - Lesson 3
C++ Course - Lesson 3Mohamed Ahmed
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentalsHCMUTE
 
ADO.NET Entity Framework by Jose A. Blakeley and Michael Pizzo
ADO.NET Entity Framework by Jose A. Blakeley and Michael PizzoADO.NET Entity Framework by Jose A. Blakeley and Michael Pizzo
ADO.NET Entity Framework by Jose A. Blakeley and Michael PizzoHasnain Iqbal
 
Linq 090701233237 Phpapp01
Linq 090701233237 Phpapp01Linq 090701233237 Phpapp01
Linq 090701233237 Phpapp01google
 
Chapter2pp
Chapter2ppChapter2pp
Chapter2ppJ. C.
 

Similar to Linq (20)

PostThis
PostThisPostThis
PostThis
 
Understanding linq
Understanding linqUnderstanding linq
Understanding linq
 
Language Integrated Query By Nyros Developer
Language Integrated Query By Nyros DeveloperLanguage Integrated Query By Nyros Developer
Language Integrated Query By Nyros Developer
 
Linq
LinqLinq
Linq
 
Embedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for JavaEmbedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for Java
 
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05
 
Linq
LinqLinq
Linq
 
Python Programming by Dr. C. Sreedhar.pdf
Python Programming by Dr. C. Sreedhar.pdfPython Programming by Dr. C. Sreedhar.pdf
Python Programming by Dr. C. Sreedhar.pdf
 
Linq in C# 3.0: An Overview
Linq in C# 3.0: An OverviewLinq in C# 3.0: An Overview
Linq in C# 3.0: An Overview
 
Python Programming
Python ProgrammingPython Programming
Python Programming
 
02basics
02basics02basics
02basics
 
C++ Course - Lesson 3
C++ Course - Lesson 3C++ Course - Lesson 3
C++ Course - Lesson 3
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
 
PHPLinq
PHPLinqPHPLinq
PHPLinq
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
Cs30 New
Cs30 NewCs30 New
Cs30 New
 
ADO.NET Entity Framework by Jose A. Blakeley and Michael Pizzo
ADO.NET Entity Framework by Jose A. Blakeley and Michael PizzoADO.NET Entity Framework by Jose A. Blakeley and Michael Pizzo
ADO.NET Entity Framework by Jose A. Blakeley and Michael Pizzo
 
Linq 090701233237 Phpapp01
Linq 090701233237 Phpapp01Linq 090701233237 Phpapp01
Linq 090701233237 Phpapp01
 
Chapter2pp
Chapter2ppChapter2pp
Chapter2pp
 

Recently uploaded

[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 

Recently uploaded (20)

[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 

Linq

  • 1. LINQ By PranayRana Blog : http://pranayamr.blogspot.com Twitter : http://twitter.com/pranayamr FaceBook : http://www.facebook.com/pages/GMind-Solution
  • 2. Overview Implicitly typed local variables Anonymous Types Object and Collection Initialization Extension Method Lambda Expression Linq
  • 3. Virtual Diagram LINQ Anonymos Types Implicitly typed local variables Extension Method Object and Collection Initialization Lambda Expression
  • 4.
  • 5.
  • 6. var x; // Error, no initializer to infer type from var y = {1, 2, 3}; // Error, collection initializer not permitted var z = null; // Error, null type not permitted
  • 7. Anonymous Types What is Anonymous types ? Create new types without defining it How to define Anonymous types ? var pranay = new { id=1, Name= "pranay rana" }; var krunal = new { id=1, Name= "krunal mevada" }; Use of it var user = from user in Users  select new { user.Name, user.Id};
  • 8. Object and Collection Initialization What is object Initialization ? create object without writing too much lengthy code and without invoking constructor. Example class Employee {   public string Name { get; set; }   public string Address { get; set; }    public Employee(){}  public Employee (string name) { Name= name;  } }
  • 9. Employee emp = new Employee() { Name="Pranay", Address="Ahmedabad"  }; or Employee emp = new Employee("Hemang") { Address="Ahmedabad"   };
  • 10. Collection Initialization List<Employee> emp = new List<Employee>       {          new Employee { Name="Pranay", Address="Ahmedabad"  },          new Employee { Name="Krunal", Address="Mevada"  },          null      };
  • 11. Extension Method What is Extesion Methods ? Allow programmer to "add" methods to existing types without creating a new derived type, recompiling, or by modifying the original type Example public static class Utilities {     public static string encryptString(this string str)     {            System.Security.Cryptography.MD5CryptoServiceProvider x = new      System.Security.Cryptography.MD5CryptoServiceProvider();            byte[] data = System.Text.Encoding.ASCII.GetBytes(str);            data = x.ComputeHash(data);            return System.Text.Encoding.ASCII.GetString(data);      } }
  • 12.
  • 13. Lambda Expression Replacement of the anonymous method available in C#2.0 Consist of single line or block of statement => is lamda expression operator Syntax ( param ) => expr(int x) = > { return x + 1 }; param => exprx=> x + 1;
  • 14. Use of Lambda expression C#2.0 by using anonymous method List<int> even =      lstNumber.FindAll( delegate(inti) { if(i%2==) return i; } But for the C#3.0 with the lambda expression it will List<int> even      = lstNumber.FindAll( i => (i%2) ==0 } In LINQ var order = orders.where( o=> o.ProcessStatus  = ProcessStatus.Completed);
  • 15. What is orm ? Object Relational Mapping Allow to map your database structure with the business layer model Hide low level database interaction details Make development easy and faster
  • 16. LINQ What is LINQ ? Language-Integrated Query  Made up to make query any source of data Some flavor of LINQ LINQ to Object {Queries performed against the in-memory data} LINQ to SQL (formerly DLinq) {Queries performed against the relation database only Microsoft SQL Server Supported} LINQ to DataSet {Supports queries by using ADO.NET data sets and data tables} LINQ to Entities {Microsoft ORM solution} LINQ to XML (formerly XLinq) { Queries performed against the XML source}
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38. SQL ISNULL function LINQ var user = from u in Users join uc in UserClients on u.Id equals uc.UserId into myuserwithclient from m in myuserwithclient.DefaultIfEmpty() select new { u.Id, FirstName= u.FirstName, LastName= u.LastName, UserId= m.UserId, MobileNo= m.MobileNo?? "N/A" };
  • 39. Selectmany Flattens the resulting sequences into one sequence users.SelectMany (       u => u.Userclient,       (u, uc) =>          new           {             Name = u.Name,             Mobileno = uc.Mobile,             IsApproved = uc.IsApproved          }    )
  • 40. Linq Deferred Execution Query not going to execute at this point var query = from customer in db.Customers where customer.City == "Paris" select customer; Query get executed when we apply method like (Count(),toList() etc.) int count = (from customer in db.Customers where customer.City == "Paris" select customer).Count();
  • 41. Questions and Query