Skip to main content

Featured Post

How to use Tabs in ASP.NET CORE

I want to show Components in a tabs , so first of all create few components. In this project we have three components, First View Component  public class AllViewComponent : ViewComponent     {         private readonly UserManager<ApplicationUser> _userManager;         public AllViewComponent(UserManager<ApplicationUser> userManager)         {             _userManager = userManager;         }         public async Task<IViewComponentResult> InvokeAsync()         {             List<StudentViewModel> allUsers = new List<StudentViewModel>();             var items = await _userManager.Users.ToListAsync();             foreach (var item in items)             {                 allUsers.Add(new StudentViewModel {Id=item.Id, EnrollmentNo = item.EnrollmentNo, FatherName = item.FatherName, Name = item.Name, Age = item.Age, Birthdate = item.Birthdate, Address = item.Address, Gender = item.Gender, Email = item.Email });             }            

Introducing LINQ Queries in ASP.NET

Language Integrated Query (LINQ) is a new component of .NET Framework. The basic function of LINQ is to add native data querying capabilities to .NET Framework by using syntax similar to Structured Query Language (SQL). LINQ allows you to define statements that query a data source to generate the requested result set.
LINQ is an attempt to provide a consistent method to obtain and manipulate data. You can use LINQ directly within the ASP.NET programming language entities called query expressions. These query expressions are based on numerous query operators that have been designed to work in a manner similar to that of SQL. LINQ defines the set of query operators, which are used to query and filter the data. The difference between LINQ and SQL is that that unlike SQL, the query expressions in LINQ can be used to interact with numerous types of data, even the data that does not belong to a relational database.

A query is an expression that retrieves the requested data from a data source. A LINQ query specifies the information that you want to retrieve from a data source. LINQ queries can also perform additional functions, such as sorting and grouping the retrieved data . The LINQ queries are written in declarative query syntax. The various clauses that you can use with the LINQ query are the From, Where, OrderBy, and Select clauses. They are the predefined clauses that you can use for the execution of a LINQ query.
The basic syntax of using a LINQ query is that the LINQ query expressions must start with the From clause and end with the Select or the Group clause. You can use the Where and OrderBy clauses to perform additional functions such as retrieving the data.

The following are three basic steps of a LINQ query execution:

1.  The first step in the LINQ query execution is to obtain the data source. The data source can be either a SQL database or an XML file.
2.  The second step is to create the query.
3.  Lastly, you need to execute your LINQ query.

Before you work with LINQ queries, you need to be aware of the following basic concepts:

□ Data Sources in LINQ Queries
□ Deferred Query Execution and Immediate Execution
□ LINQ and Generic Types

Data Sources in LINQ Queries

The data source in a LINQ query can be a data structure, a Web service, a file system, or a database. LINQ query execution is simple because the syntax and the pattern of the query do not change with the change in the data source. The different ways in which you can use LINQ with different data sources are as follows:
□ You should implement the IEnumerable<T> interface for enabling the LINQ to Objects querying.
□ You can create standard query operator methods, such as Where and Select, to enable custom LINQ queries
□ You can also create a provider for your data source that implements the IQueryable<T> interface to enable LINQ queries. A provider that implements this interface receives LINQ queries in the form of expression trees.
□ You can also create a provider that enables not only querying but also insert, update, and delete operations.

When you retrieve data using LINQ, the data source is not important. Execution of LINQ queries are independent of data types of data and structure of original data source.
LINQ previews the data source as an IEnumerable<T> or IQueryable<T> collection. For example, in LINQ to SQL, the source data is made visible as an IEnumerable<XElement> collections element. In LINQ to DataSet, the source data is made visible as an IEnumerabie<DataRow> collections."

Deferred Query Execution and Immediate Execution

The LINQ query only stores query commands. When vou define a query in LINQ during runtime, the query does not run. The query runs when the items are iterated. The query variable only stores the query commands. The actual execution of LINQ query is held back until you iterate over the query variable in a ForEach statement. This concept of holding back the actual execution is termed as deferred query execution. You can use the ForEach statement to retrieve the LINQ query results. For example, in a database that is updated continuously, you can create a LINQ query that retrieves the latest data, and you can also execute it repeatedly at different intervals to retrieve different results every time.

If the queries perform aggregation functions over a range, the elements must first iterate over the range. Ihis is called immediate execution. These functions must first iterate over the source elements and then display the result. The clauses that perform such kind of forced execution are Count, Max, Min, and Average. Unlike deferred execution, immediate execution of queries does not require an explicit ForEach statement to return the result.

If you compare deferred to immediate query execution, deferred query execution has an edge over the immediate query execution. This is because in deferred query execution the query does not hold the result. You can execute it as often as you like. You can also update the data source on a regular basis by a separate application. You can retrieve the latest data in deferred query execution. This kind of functioning is not possible in immediate query execution.

LINQ and Generic Types

The LINQ queries are based on generic types. These types were introduced with .NET Framework 2.0. The generic types are used to maximize code reuse, type safety, and performance. The most common use of generic is to create collection classes. There are two basic concepts of the generic types used in LINQ:
1.  In a LINQ query, when you create an instance of a generic collection class, such as List<T>, you replace the T with the type of objects that the list will hold. For example, a list of strings is represented as List<String> and a list of Customer object is represented as List<Customer>. A generic list provides many benefits over collections that store their elements as Objects. For example, if you try to add a Customer to a List<String>, you will get a compile-time error. In such cases, it is easy to use generic collections as you do not need to perform run-time type-casting.
2.  The second generic type that LINQ uses is the IEnumerable<T> interface. It enables the generic collection classes to be enumerated by using the ForEach loop. For example, a LINQ query variable that is typed as IEnumerable<Customer> means that when the query is executed it will produce a sequence of zero or more Customer objects.

Comments

Popular Post

Polynomial representation using Linked List for Data Structure in 'C'

Polynomial representation using Linked List The linked list can be used to represent a polynomial of any degree. Simply the information field is changed according to the number of variables used in the polynomial. If a single variable is used in the polynomial the information field of the node contains two parts: one for coefficient of variable and the other for degree of variable. Let us consider an example to represent a polynomial using linked list as follows: Polynomial:      3x 3 -4x 2 +2x-9 Linked List: In the above linked list, the external pointer ‘ROOT’ point to the first node of the linked list. The first node of the linked list contains the information about the variable with the highest degree. The first node points to the next node with next lowest degree of the variable. Representation of a polynomial using the linked list is beneficial when the operations on the polynomial like addition and subtractions are performed. The resulting polynomial can also

How to use Tabs in ASP.NET CORE

I want to show Components in a tabs , so first of all create few components. In this project we have three components, First View Component  public class AllViewComponent : ViewComponent     {         private readonly UserManager<ApplicationUser> _userManager;         public AllViewComponent(UserManager<ApplicationUser> userManager)         {             _userManager = userManager;         }         public async Task<IViewComponentResult> InvokeAsync()         {             List<StudentViewModel> allUsers = new List<StudentViewModel>();             var items = await _userManager.Users.ToListAsync();             foreach (var item in items)             {                 allUsers.Add(new StudentViewModel {Id=item.Id, EnrollmentNo = item.EnrollmentNo, FatherName = item.FatherName, Name = item.Name, Age = item.Age, Birthdate = item.Birthdate, Address = item.Address, Gender = item.Gender, Email = item.Email });             }            

Memory representation of Linked List Data Structures in C Language

                                 Memory representation of Linked List              In memory the linked list is stored in scattered cells (locations).The memory for each node is allocated dynamically means as and when required. So the Linked List can increase as per the user wish and the size is not fixed, it can vary.                Suppose first node of linked list is allocated with an address 1008. Its graphical representation looks like the figure shown below:       Suppose next node is allocated at an address 506, so the list becomes,   Suppose next node is allocated with an address with an address 10,s the list become, The other way to represent the linked list is as shown below:  In the above representation the data stored in the linked list is “INDIA”, the information part of each node contains one character. The external pointer root points to first node’s address 1005. The link part of the node containing information I contains 1007, the address of