際際滷

際際滷Share a Scribd company logo
LINQTr畉nCh鱈 KhangMicrosoft Student PartnersEmail: khangtran1990@hotmail.com
N畛IDUNGKh叩i ni畛m
Ph但n lo畉i
LINQ to Object
LINQ to XML
LINQ to Dataset
LINQ to SQL
ADO.NET
ADO.NET EntityFramework
LINQ vs ADO.NET
DEMOD畛 li畛u c坦 th畛 動畛c l動u tr畛 畛 nhi畛u n董iDatabase(SQL Server,Oracle )
XML files
File 油(Access, Excel )C叩ch giao ti畉p ?
KHI NI畛M LINQL ng担n ng畛 truy v畉n 動畛c t鱈ch h畛p vo ng担n ng畛 l畉p tr狸nh (VB, C#, ).
動a ra kh畉 nng l畉p tr狸nh m畛i trong .NET-Gi畉i ph叩p l畉p tr狸nh h畛p nh畉tfrom customer in Customerswhere油customer.Name == "Foysal"select customer
LINQ TO OBJECTS畛 d畛ng LINQ 畛 truy v畉n t畉p h畛p c叩c 畛i t動畛ng d動畛i d畉ng IEnumerable ho畉c IEnumerable<T>Without LINQWith LINQList<Students> MaleStudents = new List<Students>();Foreach(Students student in Students){  if(student.sex == male)  {    MaleStudents.Add(student	);  }}IEnumerable <Students> MaleStudents =from student in Studentswhere student.sex==maleselect student;
LINQ TO XML XmlDocumentdoc = newXmlDocument();XmlElementbooks = doc.CreateElement("books");XmlElement author = doc.CreateElement("author");author.InnerText = "Fabrice Marguerie";XmlElement price= doc.CreateElement(price");author2.InnerText = 80;XmlElement publishyear = doc.CreateElement(publishyear");author3.InnerText = 2008";XmlElementtitle = doc.CreateElement("title");title.InnerText = ABC";XmlElementbook = doc.CreateElement("book");book.AppendChild(author1);book.AppendChild(author2);book.AppendChild(author3);book.AppendChild(title);books.AppendChild(book);doc.AppendChild(books);XDocument xmlbooks = newXDocument(newXDeclaration("1.0", "UTF-16", "yes"),newXElement("books",newXElement("book", newXAttribute("id","B01"),newXElement("author", "Fabrice Marguerie"),newXElement("price", 80),newXElement("publishyear", 2008),newXElement("title", "ABC"))));<?xmlversion="1.0"encoding="utf-8" ?><books>  <book id = B01>    <title>ABC</title>    <author>Fabrice Marguerie </author><price>80</price><pulishyear>2008</pulishyear>      </book></books>
LINQ TO XML Cung c畉p 1 c担ng c畛 m畉nh m畉 trong vi畛c truy v畉nXMLvar books = from b in xmlbooks.Elements("book")	     where(String)b.Element("price") == 80                           selectnew                {                    title = (String)b.Element("tilte"),                    author = (String)b.Element("author")                };foreach (var book in books)            {Console.WriteLine(book);}
LINQ TO DATASETDATASET ?LINQ to DataSet gi炭p truy v畉n 畛i t動畛ng Dataset d畛 dng v nhanh ch坦ngvar cus = from c in customersDataset.Tables["Customers"].AsEnumerable()          select c["CustomerID"];foreach (var c in cus){   Console.WriteLine("{0}", c);}
LINQ TO SQLLINQ to SQL l m畛t phi棚n b畉n Object-Relational Mapping (ORM).DatabaseDataContextTableClassViewClassColumnField / PropertyRelationshipField / PropertyStored ProcedureMethod
L畛pDataContextL m畛t class k畉tn畛i畉nCSDL 畛 SQL Server
Chuy畛n c但u truy v畉n thnh c但u l畛nh SQL
Ad

More Related Content

Viewers also liked (20)

Lec06
Lec06Lec06
Lec06
Mohamed Yaser
Summary for the first evaluation
Summary for the first evaluationSummary for the first evaluation
Summary for the first evaluation
martamiren
Neurocirug鱈a; Marzo 2011, Volume 16Neurocirug鱈a; Marzo 2011, Volume 16
Neurocirug鱈a; Marzo 2011, Volume 16
Surgical Neurology International
Lec2 MECH ENG STRucture
Lec2    MECH ENG  STRuctureLec2    MECH ENG  STRucture
Lec2 MECH ENG STRucture
Mohamed Yaser
Proposed Changes in General-Season Deer Hunting Dec. 2, 2010 Meeting
Proposed Changes in General-Season Deer Hunting   Dec. 2, 2010 MeetingProposed Changes in General-Season Deer Hunting   Dec. 2, 2010 Meeting
Proposed Changes in General-Season Deer Hunting Dec. 2, 2010 Meeting
Utah Division of Wildlife Resources
仂亟舒亳仄 亟亠礆 从舒亰从
仂亟舒亳仄 亟亠礆 从舒亰从仂亟舒亳仄 亟亠礆 从舒亰从
仂亟舒亳仄 亟亠礆 从舒亰从
Nikita Kudelin
悋惠悋惷
 悋惠悋惷 悋惠悋惷
悋惠悋惷
Mohamed Yaser
Lec6 MECH ENG STRucture
Lec6   MECH ENG  STRuctureLec6   MECH ENG  STRucture
Lec6 MECH ENG STRucture
Mohamed Yaser
Sgcha slide share
Sgcha slide shareSgcha slide share
Sgcha slide share
Cabrini Ferraro
Tbadv492 good version
Tbadv492 good versionTbadv492 good version
Tbadv492 good version
Zach Chmill
Uni masr.com f29d8aea7936d9edc04dafcd2ad1b027
Uni masr.com f29d8aea7936d9edc04dafcd2ad1b027Uni masr.com f29d8aea7936d9edc04dafcd2ad1b027
Uni masr.com f29d8aea7936d9edc04dafcd2ad1b027
Mohamed Yaser
Problems 2
Problems 2Problems 2
Problems 2
Mohamed Yaser
Neurocirug鱈a Noviembre 2011 (Vol 17)Neurocirug鱈a Noviembre 2011 (Vol 17)
Neurocirug鱈a Noviembre 2011 (Vol 17)
Surgical Neurology International
Taco Bell ADV492
Taco Bell ADV492Taco Bell ADV492
Taco Bell ADV492
Zach Chmill
Juniper marketing
Juniper marketingJuniper marketing
Juniper marketing
Nisha Menezes
犖犖犖園犖犖劇賢犢犖犢犖犢犖犖犢犖犖朽権犖 11
犖犖犖園犖犖劇賢犢犖犢犖犢犖犖犢犖犖朽権犖 11犖犖犖園犖犖劇賢犢犖犢犖犢犖犖犢犖犖朽権犖 11
犖犖犖園犖犖劇賢犢犖犢犖犢犖犖犢犖犖朽権犖 11
犖犖巌犖園権 犖犖伍犖犖犖犖萎犖犖
忰悋悸 惡悋 惠惠惘
忰悋悸 惡悋 惠惠惘忰悋悸 惡悋 惠惠惘
忰悋悸 惡悋 惠惠惘
Mohamed Yaser
What is nanotechnology
What is nanotechnologyWhat is nanotechnology
What is nanotechnology
Mohamed Yaser
Exraindo informa巽探es de neg坦cio a partir de logs de aplica巽探es dom o ELKExraindo informa巽探es de neg坦cio a partir de logs de aplica巽探es dom o ELK
Exraindo informa巽探es de neg坦cio a partir de logs de aplica巽探es dom o ELK
Marcus Vinicius Leandro
Tutorial 2
Tutorial     2Tutorial     2
Tutorial 2
Mohamed Yaser
Summary for the first evaluation
Summary for the first evaluationSummary for the first evaluation
Summary for the first evaluation
martamiren
Neurocirug鱈a; Marzo 2011, Volume 16Neurocirug鱈a; Marzo 2011, Volume 16
Neurocirug鱈a; Marzo 2011, Volume 16
Surgical Neurology International
Lec2 MECH ENG STRucture
Lec2    MECH ENG  STRuctureLec2    MECH ENG  STRucture
Lec2 MECH ENG STRucture
Mohamed Yaser
Proposed Changes in General-Season Deer Hunting Dec. 2, 2010 Meeting
Proposed Changes in General-Season Deer Hunting   Dec. 2, 2010 MeetingProposed Changes in General-Season Deer Hunting   Dec. 2, 2010 Meeting
Proposed Changes in General-Season Deer Hunting Dec. 2, 2010 Meeting
Utah Division of Wildlife Resources
仂亟舒亳仄 亟亠礆 从舒亰从
仂亟舒亳仄 亟亠礆 从舒亰从仂亟舒亳仄 亟亠礆 从舒亰从
仂亟舒亳仄 亟亠礆 从舒亰从
Nikita Kudelin
Lec6 MECH ENG STRucture
Lec6   MECH ENG  STRuctureLec6   MECH ENG  STRucture
Lec6 MECH ENG STRucture
Mohamed Yaser
Tbadv492 good version
Tbadv492 good versionTbadv492 good version
Tbadv492 good version
Zach Chmill
Uni masr.com f29d8aea7936d9edc04dafcd2ad1b027
Uni masr.com f29d8aea7936d9edc04dafcd2ad1b027Uni masr.com f29d8aea7936d9edc04dafcd2ad1b027
Uni masr.com f29d8aea7936d9edc04dafcd2ad1b027
Mohamed Yaser
Neurocirug鱈a Noviembre 2011 (Vol 17)Neurocirug鱈a Noviembre 2011 (Vol 17)
Neurocirug鱈a Noviembre 2011 (Vol 17)
Surgical Neurology International
Taco Bell ADV492
Taco Bell ADV492Taco Bell ADV492
Taco Bell ADV492
Zach Chmill
Juniper marketing
Juniper marketingJuniper marketing
Juniper marketing
Nisha Menezes
忰悋悸 惡悋 惠惠惘
忰悋悸 惡悋 惠惠惘忰悋悸 惡悋 惠惠惘
忰悋悸 惡悋 惠惠惘
Mohamed Yaser
What is nanotechnology
What is nanotechnologyWhat is nanotechnology
What is nanotechnology
Mohamed Yaser
Exraindo informa巽探es de neg坦cio a partir de logs de aplica巽探es dom o ELKExraindo informa巽探es de neg坦cio a partir de logs de aplica巽探es dom o ELK
Exraindo informa巽探es de neg坦cio a partir de logs de aplica巽探es dom o ELK
Marcus Vinicius Leandro

Similar to LINQ presentation (20)

Linq n hibernate net-tier
Linq n hibernate net-tierLinq n hibernate net-tier
Linq n hibernate net-tier
Nguyen Tran
Linq to-sql-tutorial
Linq to-sql-tutorialLinq to-sql-tutorial
Linq to-sql-tutorial
nhieutien2014
Linq to-sql-tutorial
Linq to-sql-tutorialLinq to-sql-tutorial
Linq to-sql-tutorial
satthuech
Linq to-sql-tutorial
Linq to-sql-tutorialLinq to-sql-tutorial
Linq to-sql-tutorial
openglvn
Linq-to-sql-tutorial
Linq-to-sql-tutorialLinq-to-sql-tutorial
Linq-to-sql-tutorial
Pham Ngoc Long
Linq To Sql
Linq To SqlLinq To Sql
Linq To Sql
quyloc
Linq vnese
Linq vneseLinq vnese
Linq vnese
chienhm
Hdth07 ltudql02-linq-ep1
Hdth07 ltudql02-linq-ep1Hdth07 ltudql02-linq-ep1
Hdth07 ltudql02-linq-ep1
D滴ng inh
Th動董ng m畉i i畛n t畛
Th動董ng  m畉i i畛n t畛Th動董ng  m畉i i畛n t畛
Th動董ng m畉i i畛n t畛
gacon2009
Linq2 sql
Linq2 sqlLinq2 sql
Linq2 sql
D滴ng inh
Bi 5: Lm quen v畛i l畉p tr狸nh CSDL ASP.NET - Gi叩o tr狸nh FPT - C坦 v鱈 d畛 k竪m theo
Bi 5: Lm quen v畛i l畉p tr狸nh CSDL ASP.NET - Gi叩o tr狸nh FPT - C坦 v鱈 d畛 k竪m theoBi 5: Lm quen v畛i l畉p tr狸nh CSDL ASP.NET - Gi叩o tr狸nh FPT - C坦 v鱈 d畛 k竪m theo
Bi 5: Lm quen v畛i l畉p tr狸nh CSDL ASP.NET - Gi叩o tr狸nh FPT - C坦 v鱈 d畛 k竪m theo
MasterCode.vn
Book storeonline it-slideshares.blogspot.com
Book storeonline it-slideshares.blogspot.comBook storeonline it-slideshares.blogspot.com
Book storeonline it-slideshares.blogspot.com
phanleson
02 chuong 2 - lay du lieu theo cach connected
02   chuong 2 - lay du lieu theo cach connected02   chuong 2 - lay du lieu theo cach connected
02 chuong 2 - lay du lieu theo cach connected
truong le hung
02 chuong2-laydulieutheocachconnected-140404114611-phpapp02
02 chuong2-laydulieutheocachconnected-140404114611-phpapp0202 chuong2-laydulieutheocachconnected-140404114611-phpapp02
02 chuong2-laydulieutheocachconnected-140404114611-phpapp02
huynhtrong774129
Linq net
Linq net Linq net
Linq net
NguynSang29
Ung dung web chuong 6
Ung dung web  chuong 6Ung dung web  chuong 6
Ung dung web chuong 6
Giang Nguy畛n
WINFORM CREATTION ABOUT SOMETHING THAT AMAZING
WINFORM CREATTION ABOUT SOMETHING THAT AMAZINGWINFORM CREATTION ABOUT SOMETHING THAT AMAZING
WINFORM CREATTION ABOUT SOMETHING THAT AMAZING
baocongle204
01 chuong1-gioithieuado-140404114504-phpapp01
01 chuong1-gioithieuado-140404114504-phpapp0101 chuong1-gioithieuado-140404114504-phpapp01
01 chuong1-gioithieuado-140404114504-phpapp01
huynhtrong774129
Linq n hibernate net-tier
Linq n hibernate net-tierLinq n hibernate net-tier
Linq n hibernate net-tier
Nguyen Tran
Linq to-sql-tutorial
Linq to-sql-tutorialLinq to-sql-tutorial
Linq to-sql-tutorial
nhieutien2014
Linq to-sql-tutorial
Linq to-sql-tutorialLinq to-sql-tutorial
Linq to-sql-tutorial
satthuech
Linq to-sql-tutorial
Linq to-sql-tutorialLinq to-sql-tutorial
Linq to-sql-tutorial
openglvn
Linq-to-sql-tutorial
Linq-to-sql-tutorialLinq-to-sql-tutorial
Linq-to-sql-tutorial
Pham Ngoc Long
Linq To Sql
Linq To SqlLinq To Sql
Linq To Sql
quyloc
Linq vnese
Linq vneseLinq vnese
Linq vnese
chienhm
Hdth07 ltudql02-linq-ep1
Hdth07 ltudql02-linq-ep1Hdth07 ltudql02-linq-ep1
Hdth07 ltudql02-linq-ep1
D滴ng inh
Th動董ng m畉i i畛n t畛
Th動董ng  m畉i i畛n t畛Th動董ng  m畉i i畛n t畛
Th動董ng m畉i i畛n t畛
gacon2009
Bi 5: Lm quen v畛i l畉p tr狸nh CSDL ASP.NET - Gi叩o tr狸nh FPT - C坦 v鱈 d畛 k竪m theo
Bi 5: Lm quen v畛i l畉p tr狸nh CSDL ASP.NET - Gi叩o tr狸nh FPT - C坦 v鱈 d畛 k竪m theoBi 5: Lm quen v畛i l畉p tr狸nh CSDL ASP.NET - Gi叩o tr狸nh FPT - C坦 v鱈 d畛 k竪m theo
Bi 5: Lm quen v畛i l畉p tr狸nh CSDL ASP.NET - Gi叩o tr狸nh FPT - C坦 v鱈 d畛 k竪m theo
MasterCode.vn
Book storeonline it-slideshares.blogspot.com
Book storeonline it-slideshares.blogspot.comBook storeonline it-slideshares.blogspot.com
Book storeonline it-slideshares.blogspot.com
phanleson
02 chuong 2 - lay du lieu theo cach connected
02   chuong 2 - lay du lieu theo cach connected02   chuong 2 - lay du lieu theo cach connected
02 chuong 2 - lay du lieu theo cach connected
truong le hung
02 chuong2-laydulieutheocachconnected-140404114611-phpapp02
02 chuong2-laydulieutheocachconnected-140404114611-phpapp0202 chuong2-laydulieutheocachconnected-140404114611-phpapp02
02 chuong2-laydulieutheocachconnected-140404114611-phpapp02
huynhtrong774129
Ung dung web chuong 6
Ung dung web  chuong 6Ung dung web  chuong 6
Ung dung web chuong 6
Giang Nguy畛n
WINFORM CREATTION ABOUT SOMETHING THAT AMAZING
WINFORM CREATTION ABOUT SOMETHING THAT AMAZINGWINFORM CREATTION ABOUT SOMETHING THAT AMAZING
WINFORM CREATTION ABOUT SOMETHING THAT AMAZING
baocongle204
01 chuong1-gioithieuado-140404114504-phpapp01
01 chuong1-gioithieuado-140404114504-phpapp0101 chuong1-gioithieuado-140404114504-phpapp01
01 chuong1-gioithieuado-140404114504-phpapp01
huynhtrong774129
Ad

LINQ presentation

  • 1. LINQTr畉nCh鱈 KhangMicrosoft Student PartnersEmail: khangtran1990@hotmail.com
  • 11. DEMOD畛 li畛u c坦 th畛 動畛c l動u tr畛 畛 nhi畛u n董iDatabase(SQL Server,Oracle )
  • 13. File 油(Access, Excel )C叩ch giao ti畉p ?
  • 14. KHI NI畛M LINQL ng担n ng畛 truy v畉n 動畛c t鱈ch h畛p vo ng担n ng畛 l畉p tr狸nh (VB, C#, ).
  • 15. 動a ra kh畉 nng l畉p tr狸nh m畛i trong .NET-Gi畉i ph叩p l畉p tr狸nh h畛p nh畉tfrom customer in Customerswhere油customer.Name == "Foysal"select customer
  • 16. LINQ TO OBJECTS畛 d畛ng LINQ 畛 truy v畉n t畉p h畛p c叩c 畛i t動畛ng d動畛i d畉ng IEnumerable ho畉c IEnumerable<T>Without LINQWith LINQList<Students> MaleStudents = new List<Students>();Foreach(Students student in Students){ if(student.sex == male) { MaleStudents.Add(student ); }}IEnumerable <Students> MaleStudents =from student in Studentswhere student.sex==maleselect student;
  • 17. LINQ TO XML XmlDocumentdoc = newXmlDocument();XmlElementbooks = doc.CreateElement("books");XmlElement author = doc.CreateElement("author");author.InnerText = "Fabrice Marguerie";XmlElement price= doc.CreateElement(price");author2.InnerText = 80;XmlElement publishyear = doc.CreateElement(publishyear");author3.InnerText = 2008";XmlElementtitle = doc.CreateElement("title");title.InnerText = ABC";XmlElementbook = doc.CreateElement("book");book.AppendChild(author1);book.AppendChild(author2);book.AppendChild(author3);book.AppendChild(title);books.AppendChild(book);doc.AppendChild(books);XDocument xmlbooks = newXDocument(newXDeclaration("1.0", "UTF-16", "yes"),newXElement("books",newXElement("book", newXAttribute("id","B01"),newXElement("author", "Fabrice Marguerie"),newXElement("price", 80),newXElement("publishyear", 2008),newXElement("title", "ABC"))));<?xmlversion="1.0"encoding="utf-8" ?><books> <book id = B01> <title>ABC</title> <author>Fabrice Marguerie </author><price>80</price><pulishyear>2008</pulishyear> </book></books>
  • 18. LINQ TO XML Cung c畉p 1 c担ng c畛 m畉nh m畉 trong vi畛c truy v畉nXMLvar books = from b in xmlbooks.Elements("book") where(String)b.Element("price") == 80 selectnew { title = (String)b.Element("tilte"), author = (String)b.Element("author") };foreach (var book in books) {Console.WriteLine(book);}
  • 19. LINQ TO DATASETDATASET ?LINQ to DataSet gi炭p truy v畉n 畛i t動畛ng Dataset d畛 dng v nhanh ch坦ngvar cus = from c in customersDataset.Tables["Customers"].AsEnumerable() select c["CustomerID"];foreach (var c in cus){ Console.WriteLine("{0}", c);}
  • 20. LINQ TO SQLLINQ to SQL l m畛t phi棚n b畉n Object-Relational Mapping (ORM).DatabaseDataContextTableClassViewClassColumnField / PropertyRelationshipField / PropertyStored ProcedureMethod
  • 21. L畛pDataContextL m畛t class k畉tn畛i畉nCSDL 畛 SQL Server
  • 22. Chuy畛n c但u truy v畉n thnh c但u l畛nh SQL
  • 23. 畉m nh畉n vi畛c t動董ng t叩c v畛i CSDL
  • 24. Thay 畛i CSDLth担ng qua ph動董ng th畛c SubmitChanges().LINQTOSQLNorthwindDataContext db = newNorthwindDataContext();varquery = from c in db.Customers wherec.City == "London"selectnew { Name = c.ContactName, Country = c.Country, City = c.City };
  • 25. C畉U TRC LINQ TO SQLfrom c in db.Customerswhere c.City == "London"select new {Name, Phone};db.Customers.InsertOnSubmit(c1);c2.City = Seattle";db.Customers.DeleteOnSubmit(c3);SELECT CompanyName, PhoneFROM CustomersWHERE City == 'London'INSERT INTO CustomersUPDATE CustomersDELETE FROM Customers
  • 26. TransactionTransactionl m畛t d畛ch v畛 nh畉m 畉m b畉o r畉ng m畛t t畉p c叩c thao t叩c 畛c l畉p s畉 動畛c th畛c thi nh動 m畛t 董n v畛 duy nh畉tNorthwindDataContext db = newNorthwindDataContext(); using(TransactionScope ts = newTransactionScope()){ try { Productprod1 = db.Products.First(p => p.ProductID == 4); Productprod2 = db.Products.First(p => p.ProductID == 5);prod1.UnitsInStock -= 3;prod2.UnitsInStock -= 5;db.SubmitChanges();ts.Complete();}catch(Exception e){ Console.WriteLine(e.Message); Console.WriteLine("Error submitting changes,all changes rolled back."); } }
  • 27. DeferredExecutionvar q = from d in db.Doctors whered.City == "London"selectd;if(orderByLocation){q = from d in qorderbyd.Country, d.Cityselectd;}elseif (orderByName){q = from d in qorderby d.DoctorNameselect d;}foreach(Doctor d in q) Console.WriteLine(d.DoctorName);
  • 29. Truyc畉pCSDLv畛i ADO.NETSqlConnection connection = new SqlConnection();connection.Open();SqlCommandcmd = new SqlCommand( Select Name, Phone From Customers Where City = @city );cmd.Parameters.AddWithValue(@city, London);Datareaderdr = connection.Execute(cmd);While (dr.Read()){ string name = dr.GetString(0); string phone = dr.GetString(1);DateTime date = dr.GetDateTime(2);}dr.Close();Connection.Close();Chu畛i truy v畉nX叩c畛nhki畛ud畛li畛uk畉tqu畉
  • 32. LINQvsADO.NETLINQ l t畉p m畛 r畛ng cho ph辿p vi畉t c叩c c但u truy v畉n ngay trong c叩c ng担n ng畛 l畉p tr狸nh. ADO.NET l c担ng ngh畛 cho ph辿p c叩c 畛ng d畛ng c坦 th畛 k畉t n畛i v lm vi畛c v畛i c叩c lo畉i CSDL kh叩c nhauLINQ kh担ng ph畉i l m畛t c担ng ngh畛 動畛c t畉o ra 畛 thay th畉 ADO.NET
  • 33. DEMO

Editor's Notes