Friday 14 June 2013

LINQ Hour 5 - Queries using LINQ

Written By:-Isha Malhotra 

Our Website:-www.techaltum.com
Perform different functionality (QUERY) using LINQ

As in the previous article I already discussed about select, insert, update and delete. I also discussed with where clause, order by, grouping. In this hour I will discuss about different operation which we can perform using LINQ. As we know we can perform this functionality on array, generics, database, xml etc. so here I am taking the example of array, generics and database. I will discuss xml separately.  

To work with this functionality I am taking the following source:-
Array

Using following int array:-

int[] marks = new int[] { 23, 45, 78, 90, 56, 89, 10, 32 };

Generics:-

Using following class to implement generics:-

public class data
{
    public int roll_no;
    public string student;
    public int per;

}

And following list:-

List<data> dt = new List<data>()
        {
            new data{roll_no=1, student="isha", per=100},
            new data{roll_no=2, student="neha", per=89},
            new data{roll_no=3, student="rahul", per=34}
        };
Database

Using following table:-



Figure 1

And create its class to mapping this table which is as follows:-

[Table(Name="prod_rep")]

public class Class1
{
   
    [Column]
    public int id;
    [Column]
    public int prod_year;
    [Column]
    public string dept;
    [Column]
    public int no_of_prod;
}

click on the following link to perform different functionality:-

Part 1 Aggregate function in LINQ

Part 2 Sorting in LINQ

Part 3 Take / TakeWhile and Skip / SkipWhile


No comments:

Post a Comment