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

Using linq in c# Express

It is very common for applications to use data in SQL databases or XML documents. Traditionally, developers had to learn a primary programming language, such as C#, and a secondary language, such as SQL or XQuery. Language-Integrated Query (LINQ) brings query capabilities into the C# language itself. Now, instead of learning a separate query language, you can use your knowledge of C#, together with some additional keywords and concepts, to query SQL databases, ADO.NET datasets, XML documents, and any .NET collection class that implements the IEnumerable interface.

Advantages of Using linq

  • Familiar syntax for writing queries.

  • Compile-time checking for syntax errors and type safety.

  • Improved debugger support.

  • IntelliSense support.

  • Ability to work directly with XML elements instead of creating a container XML document, as required with W3C DOM.

  • In-memory XML document modification that is powerful, yet simpler to use than XPath or XQuery.

  • Powerful filtering, ordering, and grouping capabilities.

  • Consistent model for working with data across various kinds of data sources and formats.

Использование linq в c# Express

В приложениях часто используются данные из баз данных SQL или XML-документов. Традиционно, разработчики должны были изучить как основной язык программирования, такой как C#, так и дополнительный, например SQL или XQuery. LINQ (Language-Integrated Query) предоставляет возможность осуществлять запросы на самом языке C#. Теперь, вместо изучения отдельного языка запросов, можно выполнять запросы к базам данных SQL, наборам данных ADO.NET, XML-документам и любым классам коллекций .NET Framework, реализующих интерфейс IEnumerable, используя знание C# и нескольких дополнительных ключевых слов и основных понятий.

Преимущества использования linq

  • Знакомый синтаксис для написания запросов

  • Проверка на наличие ошибок синтаксиса и на безопасность типа при компиляции.

  • Улучшенная поддержка отладчика

  • Поддержка IntelliSense

  • Возможность напрямую работать с XML-элементами вместо создания контейнера XML-документа, что было необходимо при использовании объектной модели документа (DOM) W3C.

  • Изменение XML-документа в памяти, что более эффективно, чем простое использование XPath или XQuery.

  • Эффективные функции фильтрации, сортировки и группировки.

  • Согласованная модель для работы с источниками данными различных типов и форматов.

C# Language Enhancements that Support linq

Following are some new language structures that are added to C# 3.0 to support LINQ:

Language Structure

Description

query expressions

A declarative query syntax used to query data from any LINQ-enabled data source.

implicitly typed variables

A variable, specified with the modifier var, which enables the compiler to infer the type of the variable.

object initializers

Enables the initialization of objects without explicitly calling a constructor for the object.

anonymous types

Enables the compiler to create objects without requiring that you specify a named data type. The type name is only available to the compiler.

extension methods

Enables the extension of any existing type by associating static methods to the type.

lambda expressions

An inline expression or statement block that can be used wherever a delegate type is expected.