Bài giảng Lập trình hướng đối tượng - Chương 7: Language Integrated Query (LINQ)
Số trang: 30
Loại file: ppt
Dung lượng: 1.40 MB
Lượt xem: 13
Lượt tải: 0
Xem trước 3 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Mục tiêu của chương 7 Language Integrated Query (LINQ)nằm trong bài giảng Lập trình hướng đối tượng nhằm giới thiệu LINQ, LINQ to Object, LINQ to XML, LINQ to ADO. NET. Language Integrated Query (LINQ) là ngôn ngữ truy vấn hợp nhất trên các loại dữ liệu khác nhau.
Nội dung trích xuất từ tài liệu:
Bài giảng Lập trình hướng đối tượng - Chương 7: Language Integrated Query (LINQ)LẬP TRÌNH HƯỚNG ĐỐI TƯỢNG 2LanguageIntegratedQuery(LINQ) Nộidung Giới thiệu LINQ LINQ to Object LINQ to XML LINQ to ADO.NET GiớithiệuLINQusing System;using System.Collections.Generic;namespace Demo01{ class Program { static void Main(string[] args) {string[]greetings={hello world,hello LINQ,hello Apress }; List result = new List(); foreach (string greeting in greetings) { if (greeting.EndsWith(LINQ)) { result.Add(greeting); } } foreach (string item in result) { Console.WriteLine(item); } Console.ReadLine(); } }} Trước khi có LINQ GiớithiệuLINQusing System;using System.Linq;namespace Demo01{ class Program { static void Main(string[] args) {string[]greetings = {hello world, hello LINQ, hello Apress }; var items = from s in greetings where s.EndsWith(LINQ) select s; foreach (var item in items) Console.WriteLine(item); } }} Khi có LINQ GiớithiệuLINQ Language Integrated Query (LINQ) là ngôn ngữ truy vấn hợp nhất trên các loại dữ liệu khác nhau. Với LINQ, bạn có thể truy vấn nhiều nguồn dữ liệu khác nhau trong C#: đối tượng (object), cơ sở dữ liệu SQL, tài liệu XML, mô hình dữ liệu thực thể (entity data model). Đưa ra khả năng lập trình mới trong .NET - Giải pháp lập trình hợp nhất GiớithiệuLINQ VB C# Others… .NETLanguageIntegratedQuery LINQenableddatasources LINQenabledADO.NET LINQ LINQ LINQ LINQ LINQToObjects ToDatasets ToSQL ToEntities ToXML Objects Relational XMLLINQ provides one programming model for all types of data (objects, SQL, XML, GiớithiệuLINQ Tất cả các thao tác truy vấn LINQ gồm 3 hành động chính: Lấy nguồn dữ liệu Tạo truy vấn Thực thi truy vấn LINQ to Object Sử dụng LINQ để truy vấn tập hợp các đối tượng dưới dạng IEnumerable hoặc IEnumerableVí dụ: int[ ] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; List list; string[] str = { Visual Studio 2008, LINQ, WCF, WWF, WPF}; LINQ to Objectstatic void Main(string[] args){ int[ ] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; var lowNums = from n in numbers where n < 5 select n; Console.WriteLine(Numbers < 5:); foreach (var x in lowNums){ Console.WriteLine(x); }} LINQ to Objectstatic void Main(string[] args){string[] names = { Alonso, Zheng, Smith,Jones, Smythe, Small, Ruiz, Hsieh,Jorgenson, Ilyich, Singh, Samba, Fatimah };var queryResults = from n in names where n.StartsWith(S) select n; foreach (var item in queryResults) { Console.WriteLine(item); }} LINQ to Objectstatic void Main(string[] args){List customers = new List { new Customer { ID=A, City=New York, Country=USA, Region=North America, Sales=9999 }, new Customer { ID=B, City=Mumbai, Country=India, Region=Asia, Sales=8888 }, new Customer { ID=C, City=Karachi, Country=Pakistan, Region=Asia, Sales=7777 }};var queryResults = from c in customers where c.Region == Asia select c; foreach (Customer c in queryResults) { Console.WriteLine(c); }} LINQ to XML 1 Sách lập trình C# 1 400000 2 Sách lập trình VB 1 50000 LINQ to XML Cung cấp 1 công cụ mạnh trong việc truy vấn XMLvar sp = (from c in XElement.Load(SanPham.xml).Elements(SanPham) select new { MaSanPham = (string)c.Element(MaSanPham), TenSanPham = (string)c.Element(TenSanPham), MaLoai = (string)c.Element(MaLoai), DonGia = (string)c.Element(DonGia), }).ToArray(); dgSanPham.DataSource = sp; LINQ to DataSet LINQ to DataSet giúp truy vấn đối tượng Dataset dễ dàng và nhanh chóngstring str = server = localhost; data ...
Nội dung trích xuất từ tài liệu:
Bài giảng Lập trình hướng đối tượng - Chương 7: Language Integrated Query (LINQ)LẬP TRÌNH HƯỚNG ĐỐI TƯỢNG 2LanguageIntegratedQuery(LINQ) Nộidung Giới thiệu LINQ LINQ to Object LINQ to XML LINQ to ADO.NET GiớithiệuLINQusing System;using System.Collections.Generic;namespace Demo01{ class Program { static void Main(string[] args) {string[]greetings={hello world,hello LINQ,hello Apress }; List result = new List(); foreach (string greeting in greetings) { if (greeting.EndsWith(LINQ)) { result.Add(greeting); } } foreach (string item in result) { Console.WriteLine(item); } Console.ReadLine(); } }} Trước khi có LINQ GiớithiệuLINQusing System;using System.Linq;namespace Demo01{ class Program { static void Main(string[] args) {string[]greetings = {hello world, hello LINQ, hello Apress }; var items = from s in greetings where s.EndsWith(LINQ) select s; foreach (var item in items) Console.WriteLine(item); } }} Khi có LINQ GiớithiệuLINQ Language Integrated Query (LINQ) là ngôn ngữ truy vấn hợp nhất trên các loại dữ liệu khác nhau. Với LINQ, bạn có thể truy vấn nhiều nguồn dữ liệu khác nhau trong C#: đối tượng (object), cơ sở dữ liệu SQL, tài liệu XML, mô hình dữ liệu thực thể (entity data model). Đưa ra khả năng lập trình mới trong .NET - Giải pháp lập trình hợp nhất GiớithiệuLINQ VB C# Others… .NETLanguageIntegratedQuery LINQenableddatasources LINQenabledADO.NET LINQ LINQ LINQ LINQ LINQToObjects ToDatasets ToSQL ToEntities ToXML Objects Relational XMLLINQ provides one programming model for all types of data (objects, SQL, XML, GiớithiệuLINQ Tất cả các thao tác truy vấn LINQ gồm 3 hành động chính: Lấy nguồn dữ liệu Tạo truy vấn Thực thi truy vấn LINQ to Object Sử dụng LINQ để truy vấn tập hợp các đối tượng dưới dạng IEnumerable hoặc IEnumerableVí dụ: int[ ] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; List list; string[] str = { Visual Studio 2008, LINQ, WCF, WWF, WPF}; LINQ to Objectstatic void Main(string[] args){ int[ ] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; var lowNums = from n in numbers where n < 5 select n; Console.WriteLine(Numbers < 5:); foreach (var x in lowNums){ Console.WriteLine(x); }} LINQ to Objectstatic void Main(string[] args){string[] names = { Alonso, Zheng, Smith,Jones, Smythe, Small, Ruiz, Hsieh,Jorgenson, Ilyich, Singh, Samba, Fatimah };var queryResults = from n in names where n.StartsWith(S) select n; foreach (var item in queryResults) { Console.WriteLine(item); }} LINQ to Objectstatic void Main(string[] args){List customers = new List { new Customer { ID=A, City=New York, Country=USA, Region=North America, Sales=9999 }, new Customer { ID=B, City=Mumbai, Country=India, Region=Asia, Sales=8888 }, new Customer { ID=C, City=Karachi, Country=Pakistan, Region=Asia, Sales=7777 }};var queryResults = from c in customers where c.Region == Asia select c; foreach (Customer c in queryResults) { Console.WriteLine(c); }} LINQ to XML 1 Sách lập trình C# 1 400000 2 Sách lập trình VB 1 50000 LINQ to XML Cung cấp 1 công cụ mạnh trong việc truy vấn XMLvar sp = (from c in XElement.Load(SanPham.xml).Elements(SanPham) select new { MaSanPham = (string)c.Element(MaSanPham), TenSanPham = (string)c.Element(TenSanPham), MaLoai = (string)c.Element(MaLoai), DonGia = (string)c.Element(DonGia), }).ToArray(); dgSanPham.DataSource = sp; LINQ to DataSet LINQ to DataSet giúp truy vấn đối tượng Dataset dễ dàng và nhanh chóngstring str = server = localhost; data ...
Tìm kiếm theo từ khóa liên quan:
Ngôn ngữ truy vấn Ngôn ngữ LINQ Lập trình hướng đối tượng Tài liệu lập trình hướng đối tượng Cơ bản lập trình hướng đối tượng Bài giảng lập trình hướng đối tượng chương 7Gợi ý tài liệu liên quan:
-
Giáo trình Lập trình hướng đối tượng: Phần 2
154 trang 275 0 0 -
101 trang 200 1 0
-
14 trang 134 0 0
-
Giáo trình lập trình hướng đối tượng - Lê Thị Mỹ Hạnh ĐH Đà Nẵng
165 trang 112 0 0 -
Giáo trình Lập trình Windows 1 - Trường CĐN Đà Lạt
117 trang 96 0 0 -
Giáo trình Phân tích, thiết kế hướng đối tượng với UML: Phần 1 - Trường ĐH Công nghiệp Quảng Ninh
111 trang 95 0 0 -
265 trang 80 0 0
-
Giáo trình Lập trình hướng đối tượng với Java: Phần 2 - Trần Thị Minh Châu, Nguyễn Việt Hà
141 trang 75 0 0 -
33 trang 69 0 0
-
Bài giảng Cơ sở dữ liệu - Nguyễn Quỳnh Chi
189 trang 62 0 0