Friday, 14 June 2013

LINQ Hour 5 - Queries using LINQ

Written By:-Isha Malhotra 

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:-

Using following int array:-

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


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}

Using following table:-

Figure 1

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


public class Class1
    public int id;
    public int prod_year;
    public string dept;
    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

1 comment: