Author Archives: Pranay Rana

About Pranay Rana

Pranay is MVB on DZone and working as a Senior Software engineer. Doing Web development using Asp.Net ,C#, MS sql server, JQuery/Javascript that he had experience of 4.3 years now. For himdef. of programming is : Programming is something that you do once and that get used by multiple for many years You can visit him on his blog - Follow on twitter : @pranayamr

Generate thousand of request

Lastly I was working on the project where I have to designed web page which is exposing some set of the functions and which is get consume by some external application like java and flex. It’s worked fine and providing the output I want.

But now I want to perform the load test, so for that I want to generate thousand of request which consume the page and show me how it works. But the problem is how to generate the request because I don’t have that many people who can make request at given time.
Continue reading

Get time of Code Execution Using StopWatch

During Development of the application/product or after deployment of the application/product there might be a situation where you want to find out the the how much time is taken by you code to execute ? Is it too much slow ?

Answer to this problem is make use of StopWatch class of System.Diagnostics namespace which is usefull to find out the time taken to execute given line of code. The class is helpfull to find out how efficient code develop by measuring the time of execution.
Continue reading

Help yourself in Debugging by using Call Stack and Immediate Window

Here I am going to show you the two important window of the Visual Studio which is useful when you debugging the project and to get the result on the fly during debug mode.
Call Stack Window
Most of the developer get confuse when they are debugging application “From which function call came from up to my debug point”, this happens when they are working the code design by some one else or debugging code of the dll.
Continue reading

Ordering data in LINQ Queries by more than one column

In this post I am going to show how to do ordering when you require to order data by using the multiple columns.
By using .Orderby(x=>x.Columnname) in the LINQ query we can easily order data of the source collection. So most of new developer make use of the same function two time .Orderby(x=>x.Columnname).Orderby(x=>x.Columnname) and thinks that will do the ordering on the multiple columns.
Continue reading

IQueryable Vs. IEnumerable in terms of LINQ to SQL queries

Few days ago I was working on my project which is having Linq to Sql as database layer. I got requirement to get the first of all employee who’s designation starts with “soft”.

I get fired below query and got the result in IEnumerable varible

IEnumerable<employee> emp = 
         dc.Employees.Where(x => x.Desc.StartsWith("soft"));
emp = emp.Take(1);

But later on I found there it’s taking too much time to get the count.
Continue reading

Into and let in LINQ ( Let vs Into)

In this post I am going to show two keyword of the C# 3.0 is very helpful when playing with the set of object collection using LINQ feature.

Into keyword allows creating a temporary variable to store the results of a group, join or select clause into a new variable.

var em = from e in emp
                      group e by new{ e.DeptId}
                          into gEmp
                          where gEmp.Count() > 1
                       select new { gEmp.Key.DeptId, salary = gEmp.Sum(t => t.Salary) };

Continue reading

Dynamic query with Linq

In this post I am going to discuss about building dynamic query with the LINQ. LINQ to SQL allow user to query data from the database without writing sql queries by writing LINQ queries. LINQ represent each table as one entity and where LINQ queries allows to manipulate data in type safe.

But Static LINQ queries not able to meet all our programming needs. A Dynamic LINQ queries is needed when we need to retrieve a set of records based on different search parameters.

For example – An employee search screen or a general purpose report which needs to execute a different SELECT statement based on a different WHERE as well as Sorting column to sort data.
Continue reading

Default Extension methods

In this post I am going to discuss about Default extension method(s) which are use full when we query the data form the collection,array or performing operation while code using linq to sql.

In .net framework there are number of extension methods which allows perform function on the the collection. But problem arise when we don’t know the collection or array empty or there is no element after we apply filter.

Methods like .First<t>(),.Last<t>(),.Single<t>() always throws exception InvalidOperationException when object collection is empty or if there is no element available after applying filter condition.

List&lt;int&gt; lstInt = new List&lt;int&gt;(new int[] {15,11,20,30});
var data = lstInt.Single(i =&gt; i &lt; 10);

Continue reading

Difference between two Entity Set using LINQ

In this tips I have discussed about how to get the difference between two table/ entity sets. As for example we want to get rows form table_A which are not exists in table_B. (When table_A primarykey is part of table_B foreignkey).

Following is way to get the row(s) form table_A which are not part of table_B

FROM Table_A A
ON A.Key = B.Key

In Linq to Sql you can achieve same thing just by calling one function Except.

var infoQuery =
    (from tblA in db.Table_A
    select tblA.Key)
        (from tblB in db.Table_B
        select tblB.Key);

So by using above query you can easily achieve task of getting difference between set of collection.