Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Учебник_ПОА.doc
Скачиваний:
93
Добавлен:
13.02.2015
Размер:
2.65 Mб
Скачать

Linq to sql

Use LINQ to SQL to access SQL Server and SQL Server Express databases through a strongly-typed object layer that you create by using the O/R Designer.

You can use the O/R Designer to map LINQ to SQL classes to tables in a database and then write LINQ queries to bind data to controls in your application. For example, the following LINQ query binds the results of a LINQ query (all customers from the United States) to a binding source of a DataGridView control.

var CustomersQuery = from customers in northwindSampleDataContext1.Customers

where customers.Country == "US"

select customers;

customerBindingSource.DataSource = CustomersQuery;

Note:

The O/R Designer currently does not support SQL Server Compact 3.5 databases.

Linq to DataSet

The DataSet is used to bind data to controls in an application. Rather than connecting directly to the database, the DataSet enables an application to use off-line (cached) data, or subsets of several data sources. When the application is brought online, the changes in the DataSet can be updated in the database.

LINQ to Dataset makes querying over cached data faster and easier than the filtering and sorting methods available to a DataSet.

Linq to xml

LINQ to XML enables you to create and modify XML documents easily by using LINQ query expressions instead of XPath or XQuery. LINQ to XML is a new in-memory XML programming API that uses modern programming constructs instead of the W3C Document Object Model (DOM).

Linq to sql

Используйте LINQ to SQL для доступа к базам данных SQL Server и SQL Server Express через строго типизированный объектный слой, создаваемый с помощью Объектно-реляционного конструктора.

Можно использовать Объектно-реляционный конструктор для сопоставления классов LINQ to SQL таблицам в базе данных и затем создавать запросы LINQ для привязки данных к элементам управления в приложении. Например, следующий запрос LINQ связывает результаты запроса LINQ (все клиенты из США) с источником привязки элементом управления DataGridView.

var CustomersQuery = from customers in northwindSampleDataContext1.Customers

where customers.Country == "US"

select customers;

customerBindingSource.DataSource = CustomersQuery;

Примечание.

Объектно-реляционный конструктор в данный момент не поддерживает базы данных SQL Server Compact 3.5.

Linq to DataSet

DataSet используется для привязки данных к элементам управления в приложении. Вместо непосредственного подключения к базе данных можно использовать DataSet для создания автономного кэша данных или подмножества нескольких источников данных. Когда приложение переводится в интерактивный режим, изменения в DataSet будут сделаны в базе данных.

LINQ to Dataset выполняет запросы кэшированных данных быстрее и легче, чем методы фильтрации и сортировки, доступные для DataSet.

LINQ to XML

LINQ to XML позволяет легко создавать и изменять XML-документы с помощью выражений запросов LINQ вместо использования XPath и XQuery. LINQ to XML является новым программным API для XML в памяти, использующим современные конструкции программирования вместо W3C Document Object Model (DOM).

C# Language Primer

Inside a C# Program

In order to understand how a C# program works, let's examine the traditional "Hello World!" program, dealing with each line of C# code in turn.

Hello World, C# Style

The C# language uses classes to organize and package code. In fact, all executable C# code must be contained in a class, even in a short program like "Hello World!" Here is the complete program that displays "Hello World!" in the console window.

using System;

// A "Hello World!" program in C#

namespace HelloWorld

{

class Hello

{

static void Main()

{

System.Console.WriteLine("Hello World!");

}

}

}