Tài liệu hướng dẫn giảng dạy dành cho giảng viên về Microsoft .NET Framework 3.5

Bộ giáo trình này được biên soạn dựa trên những tài liệu mới nhất về .NET framework 3.5 nhằm cung cấp cho sinh viên công nghệ thông tin những kiến thức cơ bản nhất về .NET framework. Nội dung bao gồm kiến trúc .NET framework, sự phát triển của .NET framework qua các phiên bản, kiến trúc phiên bản 3.5, các nội dung cơ bản trong phiên bản 3.5. Đặc biệt, giáo trình đi sâu vào Language Integrated Query (LINQ), Windows Presentation Foundation (WPF) là các công nghệ mới rất tiêu biểu của Microsoft .NET nhằm cung cấp cho sinh viên những kĩ năng cơ bản nhất để phát triển các ứng dụng trên nền .NET framework 3.5.

Những mục tiêu chính mà giáo trình cố gắng đạt được:

1. Cung cấp cho sinh viên một cái nhìn tổng quan về kiến trúc .NET framework, nắm được sự phát triển qua từng phiên bản của .NET framework, so sánh các phiên bản.

2. Giúp sinh viên nắm được một số nội dung cơ bản trong .NET framework 3.5, sự khác biệt của nó so với các phiên bản trước.

3. Hướng dẫn cho sinh viên các kỹ thuật lập trình cơ bản với 2 công nghệ quan trọng là LINQ và WPF.

 

Vì được bố cục trong 45 tiết dạy nên giáo trình không thể đi sâu vào chi tiết từng nội dung trong .NET framework mà chỉ dừng ở mức giới thiệu các khái niệm cơ bản nhất. Đối với phiên bản 3.5, giáo trình xoáy sâu vào 2 nội dung cơ bản là LINQ và WPF là các công nghệ thường gặp nhất đối với người lập trình trên .NET framework 3.5.

 

Bộ giáo trình được biên soạn và tổng hợp bao gồm: slide bài giảng, bài exercise, bài thực hành lab và các Video tự học. Ở đây, toàn bộ giáo trình đều được trình bày bằng tiếng Anh, nhằm mục đích nâng cao khả năng tiếp thu và phát triển các kỹ năng học và nghiên cứu bằng tiếng Anh – các kỹ năng vô cùng quan trọng đối với người học công nghệ thông tin.

Giáo trình có thể dùng tham khảo cho các ngành Công nghệ thông tin, điện tử, viễn thông.

 

doc63 trang | Chuyên mục: ASP.NET | Chia sẻ: dkS00TYs | Lượt xem: 2290 | Lượt tải: 1download
Tóm tắt nội dung Tài liệu hướng dẫn giảng dạy dành cho giảng viên về Microsoft .NET Framework 3.5, để xem tài liệu hoàn chỉnh bạn click vào nút "TẢI VỀ" ở trên
s-through of the source objects, a single-field narrowing, or any combination of fields in a new object. In the DatabaseQuery method, delete most of the body so that it appears thus:
static void DatabaseQuery()
{
 Northwind db = new Northwind(
 @"C:\Program Files\LINQ Preview\Data\Northwnd.mdf");
 Console.ReadLine();
}
Add the following lines to create a direct projection:
static void DatabaseQuery()
{
 Northwind db = new Northwind(
 @"C:\Program Files\LINQ Preview\Data\Northwnd.mdf");
 var productsWithCh =
	from p in db.Products
 	where p.ProductName.Contains("Ch")
 	select p;
 Console.ReadLine();
}
As written, this query will first restrict the source data based on ProductName, then select the entire Product.
Add the following lines to create a single-value projection:
static void DatabaseQuery()
{
 Northwind db = new Northwind(
 @"C:\Program Files\LINQ Preview\Data\Northwnd.mdf");
 var productsWithCh = 
 from p in db.Products
 where p.ProductName.Contains("Ch")
 select p;
 var productsByName =
	db.Products.
 Where(p => p.UnitPrice < 5).
 Select( p => p.ProductName );
 Console.ReadLine();
}
This query restricts based on the unit price, then returns a sequence of product names.
Add the following lines to create a multi-value projection by using an anonymous type:
static void DatabaseQuery()
{
 Northwind db = new Northwind(
 @"C:\Program Files\LINQ Preview\Data\Northwnd.mdf");
 var productsWithCh =
	from p in db.Products
 	where p.ProductName.Contains("Ch")
 	select p;
 var productsByName =
	db.Products.
 	Where(p => p.UnitPrice < 5).
 	Select( p => p.ProductName );
 var productsDetails =
	db.Products.
 	Where(p => p.Discontinued).
 Select(p => new {p.ProductName, p.UnitPrice});
 Console.ReadLine();
}
The returned type in this example is never declared as a type. It is created by the compiler based on the data types specified. 
Finally, display the results with the following code:
static void DatabaseQuery()
{
 Northwind db = new Northwind(
 @"C:\Program Files\LINQ Preview\Data\Northwnd.mdf");
 var productsWithCh =
	from p in db.Products
 	where p.ProductName.Contains("Ch")
 	select p;
 var productsByName =
	db.Products.
 Where(p => p.UnitPrice < 5).
 Select( p => p.ProductName );
 var productsDetails = 
	db.Products.
 	Where(p => p.Discontinued).
 Select(p => new {p.ProductName, p.UnitPrice });
 Console.WriteLine(">>Products containing Ch");
 foreach(var product in productsWithCh)
 {
 Console.WriteLine("{0}, {1}",
	product.ProductName, product.ProductID);
 }
 Console.WriteLine("\n\n>>Products names only");
 foreach(var product in productsByName)
	Console.WriteLine(product);
 Console.WriteLine("\n\n>>Products as new types");
 foreach(var product in productsDetails)
 {
 Console.WriteLine("{0}, {1}",
	product.ProductName, product.UnitPrice);
 }
 Console.ReadLine();
}
Press F5 to debug the application and view the results
Task 4 – Working with the Where Operator
The Where operator filters a sequence of values based on a predicate. It enumerates the source sequence yielding only those values that match the predicate. In the DatabaseQuery method, delete most of the body so that it appears thus:
static void DatabaseQuery()
{
 Northwind db = new Northwind(
 @"C:\Program Files\LINQ Preview\Data\Northwnd.mdf");
 Console.ReadLine();
}
The Where operator can filter based on any predicate. Enter the following code to filter the employee based on birthdate:
static void DatabaseQuery()
{
 Northwind db = new Northwind(
 @"C:\Program Files\LINQ Preview\Data\Northwnd.mdf");
 var janBirthdays = 
	db.Employees.
	Where(e => e.BirthDate.Value.Month == 1);
 foreach(var emp in janBirthdays)
 {
 Console.WriteLine("{0}, {1}", emp.LastName, emp.FirstName);
 }
 Console.ReadLine();
}
Press F5 to debug the application and view the results
Task 5 – Working with the Count Operator
The Count operator simply returns the number of elements in a sequence. This can be applied to the collection itself, or chained to other operators such as Where to count a restricted sequence. In the DatabaseQuery method, delete most of the body so that it appears thus:
static void DatabaseQuery()
{
 Northwind db = new Northwind(
 @"C:\Program Files\LINQ Preview\Data\Northwnd.mdf");
 Console.ReadLine();
}
Add the following code to count the number of elements in the Customers table:
static void DatabaseQuery()
{
 Northwind db = new Northwind(
 @"C:\Program Files\LINQ Preview\Data\Northwnd.mdf");
 int before = db.Customers.Count();
 int after = db.Customers.Where(c => c.City == "London").Count();
 int after2 = db.Customers.Count(c => c.City == "London");
 Console.WriteLine("Before={0}, After={1}/{2}",
	before, after, after2);
 Console.ReadLine();
}
Notice that the restriction can occur prior to Count being invoked. It can also take effect directly within the call to Count. 
Press F5 to debug the application and view the results
Task 6 – Working with the All and Any Operators
The All and Any operators check whether any or all elements of a sequence satisfy a condition. The Any operator returns as soon as a single matching element is found. In the DatabaseQuery method, delete most of the body so that it appears thus:
static void DatabaseQuery()
{
 Northwind db = new Northwind(
 @"C:\Program Files\LINQ Preview\Data\Northwnd.mdf");
 Console.ReadLine();
}
Like the Count operator, the All and Any operators can be invoked on any condition, and can further restrict their scope by passing a predicate directly in the invocation. Add the following code to demonstrate both operators:
static void DatabaseQuery()
{
 Northwind db = new Northwind(
 @"C:\Program Files\LINQ Preview\Data\Northwnd.mdf");
 var cust1 = db.Customers.Where(c => c.Orders.Any());
 var cust2 =
	db.Customers.
	Where(c => c.Orders.All(o => o.Freight < 50));
 foreach( var cust in cust1 )
	Console.WriteLine("{0}", cust.ContactName);
 Console.WriteLine("-----");
 foreach( var cust in cust2 )
	Console.WriteLine("{0}", cust.ContactName);
 Console.ReadLine();
}
In this case, the Any operator is used within the Where operator of another expression. This is perfectly legal as the operator is still being called on a sequence, c.Orders. This is used to return a sequence of all customers who have placed any orders. The All operator is used to return customers whose orders have all had freight costs under $50.
Press F5 to debug the application and view the results
Task 7 – Working with the ToArray and ToList Operators
The ToArray and ToList operators are convenience operators designed to convert a sequence to a typed array or list, respectively. In the DatabaseQuery method, delete most of the body so that it appears thus:
static void DatabaseQuery()
{
 Northwind db = new Northwind(
 @"C:\Program Files\LINQ Preview\Data\Northwnd.mdf");
 Console.ReadLine();
}
These operators are very useful for integrating queried data with existing libraries of code. They are also useful when you want to cache the result of a query. Start by creating a sequence:
static void DatabaseQuery()
{
 Northwind db = new Northwind(
 @"C:\Program Files\LINQ Preview\Data\Northwnd.mdf");
 var customers = db.Customers.Where(c => c.City == "London");
 Console.ReadLine();
}
Note that the sequence could even be as simple as db.Customers. Restricting the results is not a necessary component to use ToArray or ToList.
Next, simply declare an array or List collection, and assign the proper values using the appropriate operator:
static void DatabaseQuery()
{
 Northwind db = new Northwind(
 @"C:\Program Files\LINQ Preview\Data\Northwnd.mdf");
 var customers = db.Customers.Where(c => c.City == "London");
 Customer[] custArray = customers.ToArray();
 List custList = customers.ToList();
 Console.ReadLine();
}
Lab Summary
In this lab you performed the following exercises.
Using LINQ with In-Memory Collections
DLinq: LINQ for Connected Databases
XLinq: LINQ for XML Documents
Understanding the Standard Query Operators
You saw how the LINQ framework and features seamlessly tie together data access and manipulation from a variety of sources. LINQ allows you to work with in-memory objects with the power of SQL and the flexibility of C#. DLinq further builds on this support to link your objects to database tables with little extra effort. Finally XLinq brings XML query abilities with the features of XPath, but the ease of C#. The large collection of standard query operators offers built-in options for data manipulation that would have required extensive custom code in the past. Using the LINQ additions to C#, querying and transforming data in a variety of formats is easier than ever.
Kết luận
Công nghệ .NET của Microsoft là một công nghệ mạnh mẽ và liên tục được phát triển. .NET framework là cái lõi nền tảng để làm việc với .NET nên đây là một nội dung rất quan trọng, cần được giới thiệu rộng rãi với sinh viên công nghệ thông tin và các ngành khác có liên quan.
Giáo trình .NET framework 3.5 chỉ được soạn cho thời gian 45 tiết trong khi các nội dung trong đó có thể tách thành các khóa học riêng biệt, ví dụ như LINQ hay WPF, WCF... Chính bởi vậy giáo trình không thể đi hết các nội dung quan trọng của .NET framework mà chỉ mang tính chất giới thiệu cho sinh viên một số kĩ năng cơ bản ứng với một số công nghệ nổi bật của .NET framework 3.5. Nếu có điều kiện, giáo viên nên tách một số phần quan trọng trong .NET framework 3.5 thành các giáo trình riêng như LINQ, WPF, WCF, ASP.NET AJAX hay đưa thêm vào một số công nghệ khác như WF, CardSpace...
Vì thời gian thực hiện bộ giáo trình còn hạn chế và đây chỉ là version đầu tiên nên trong giáo trình vẫn còn nhiều thiếu sót. Trong thời gian tới chúng tôi sẽ cố gắng hoàn thiện giáo trình hơn nữa. Rất mong nhận được các ý kiến đóng góp của tất cả mọi người.

File đính kèm:

  • docTài liệu hướng dẫn giảng dạy dành cho giảng viên về Microsoft .NET Framework 3.5.doc
Tài liệu liên quan