What are the data sources we can query using LINQ?
Linq as the name signifies is a query feature in visual studio. A query, as we all know is performed against a data source. It is versatile because it can work against many data sources. This feature of linq has enabled programmers to use in their applications which need to work with varied data sources.
When we say datasources here, we mean varied datasources such as objects, XML documents and databases. For a data source to become retrievable by a LINQ query, it should implement either IEnumerable or IEnumerable<T> interface. By default, the Array, List<T>, and Dictionary<K,T> data sources implement the IEnumerable and IEnumerable<T> interfaces. So, they become valid data sources for a LINQ query.
LINQ queries will also work on custom types which implement IEnumerable<T> interface. When developing ERP applications, programmers use custom types when general collections are not sufficient to meet a programming requirement.
A significant advantage of this querying technology is that a same query against SQL database or a collection or a DataSet and many other types of data stores. For programmers who have worked on different technologies for writing queries Linq provides a feature to write similar queries in C#.
There are five types of queries we can write depending on the type of data source we need to query.
- LINQ to Objects queries to query in-memory data-structures like Arrays, Lists and Objects.
- LINQ to SQL queries to query the sql server database. A sql server database is a software which stores data in an organized format enabling easy access to the individual data items. The manner in which data is stored is relational which means that individual data items are related to each other.
- LINQ to Datasets to query the data in the Datasets. A dataset is an in-memory datastore which is created and destroyed during the working of an application. Similar to a relational database such as SQL server or Oracle, a Dataset holds data in a tabular format.
- LINQ to Entities queries to query a list of entities created by Entity Data Model . The EDM is a more recent creation of Microsoft and describes a data structure. Note that the EDM is not concerned with the form in which data is stored. LINQ to Entities queries work with the data structure and retrieve data from the database.
- LINQ to XML queries to query XML documents. An XML document is a unique document which can be read by both machines and humans. This is possible by formatting the document in a standardized format which is laid down by W3c organization and these formats are followed by all software companies.
Programmers use the above mentioned query types to retrieve data from various data stores and present them to the application user, using controls such as GridView, ListBox and FormView controls.