Archive for the ‘Uncategorized’ Category

LINQ # 10 – Join with multiple columns of the same table using Linq


While using LINQ as Linq to Sql queries , We often come across a scenario where we have to join the same table for multiple columns in it.

Following example illustrates how we can achieve it in Linq :

We have two tables Table1 and Table2 with columns column1 and column2 and we  have to join the Table1 with Table2 for both the columns.

We can achieve it using AnonymousType introduced by Microsoft.

Following is the code used for it


Join with multiple columns
  1. var lstDetails=(from tbl1 in Table1
  2.                 join tbl2 in  Table2
  3.                 on new {tbl1.column1,tbl1.column2}
  4.                 equals new {tbl2.column1,tbl2.column2}
  5.                 select tbl1 );

Thanks,                                                                                                                                          Ganesh


ASP.NET–Asynchronous HTTP Module

January 27, 2012 2 comments

Hi Friends,

An HTTP module is an object that sits in the ASP.NET pipeline, where it can see-and even modify-incoming requests and outgoing responses.

Today while working with website containing multiple applications , I faced a scenario where i need to  log incoming requests in database . By collecting the login name, a date and time, and the application that the user accessed during the login session.

By thinking on above scenario one would say what’s a big deal in this!! we can make entry every time the user clicks on the application .but problem with this solution is it would give call to the database every time user clicks on any application. First, it performs database insert. Second, it uses a request-processing thread to perform the I/O-a thread that could otherwise be used to service additional incoming requests, which imposes a penalty on throughput.

So for this we decided to write a http module which made it possible for us, but Question is How httpModule improve our performance / throughput the answer is ASYNCHRONOUS HttpModule.

Asynchronous Http Module
  1. public class AsyncModule : IHttpModule
  2.     {
  3.         /// <summary>
  4.         /// You will need to configure this module in the web.config file of your
  5.         /// web and register it with IIS before being able to use it. For more information
  6.         /// see the following link:
  7.         /// </summary>
  8.         #region IHttpModule Members
  10.         string conString = "Data Source=localhost;initial catalog=OpenLDAP;integrated security=true;Asynchronous Processing=true";
  11.         SqlConnection con;
  12.         SqlCommand cmd;
  15.         public void Dispose()
  16.         {
  17.             if (con != null)
  18.                 con.Close();
  19.         }
  21.         public void Init(HttpApplication context)
  22.         {
  23.             context.AddOnPreRequestHandlerExecuteAsync(new BeginEventHandler(OnBeginAsync), new EndEventHandler(OnEndAsync));
  24.         }
  26.         #endregion
  28.         public void OnLogRequest(Object source, EventArgs e)
  29.         {
  30.             //custom logging logic can go here
  31.         }
  32.         IAsyncResult OnBeginAsync(Object source, EventArgs e, AsyncCallback cb, Object state)
  33.         {
  35.             //Write your logic here to track the Request//
  36.             con = new SqlConnection(conString);
  37.             con.Open();
  38.             cmd = new SqlCommand();
  39.             cmd.Connection = con;
  40.             cmd.CommandText = "Insert into documents values('abstract3','title',null)";
  41.             return cmd.BeginExecuteNonQuery(cb, state);
  43.         }
  44.         public void OnEndAsync(IAsyncResult result)
  45.         {
  46.             cmd.EndExecuteNonQuery(result);
  48.         }
  50.     }

How above module works asynchronous???

Its Init method calls HttpApplication.AddOnPreRequestHandlerExecuteAsync in order to register begin and end methods for PreRequestHandlerExecute events.

The HttpApplication class features other AddOn methods for other per-request events. For example, an HTTP module can call AddOnBeginRequestAsync to register async handlers for BeginRequest events.

AsyncRequestLogModule’s OnBeginAsync method uses the framework’s BeginExecuteNonQuery method to begin an asynchronous insert. The moment OnBeginAsync returns, the thread goes back into the thread pool.

Thank You,

Hope this helps Smile

Categories: Uncategorized

WCF # 15 – WCF Service Behaviour Introduction (Exporting and Publishing Metadata)[Part II]

November 3, 2011 1 comment

Hi Friends,

In our last post Service Behaviour [Part – I] we learned how Concurrency and Instancing are important in improving the performance of a WCF Service.

In this article we will go through the MetaData Service Behavior.

The ABC’s of Endpoints – its addresses, bindings, and contracts—are represented in metadata so that potential clients know where, how, and what to communicate. This information is collectively referred to as service metadata.

Metadata is –

  1. The operations [WCF Methods] a service have.
  2. The structure of the data types that the methods take as input or return
  3. Definitions of all the Endpoints implemented by the service and the various options needed for each such as security

* Two steps are necessary to make metadata useful for clients:

1) Export it in a format that they can read and publish it somewhere that they can find it.
The default export format is WSDL, so as long as clients can read standardsbased
metadata format, they can understand how to communicate with the

2) WCF publishes the metadata using the WS-MetadataExchange protocol over any supported transport, or it can publish the metadata in response to an HTTP GET. Both of these steps, the export and publishing the metadata, are implemented by the ServiceMetadataBehavior in a service.

* Metadata is exposed from a service through a Metadata Exchange (MEX) endpoint. A MEX endpoint is like any other WCF endpoint: It has an address, a binding, and a contract. Like any other endpoint, a MEX endpoint can be added to a service either through configuration or through code.

A MEX endpoint should expose the IMetadataExchange interface as its
contract.this interface provides methods that inspect a service and expose its metadata as WSDL.

A number of system-supplied bindings are available for MEX endpoints, such as mexHttpBinding,mexHttpsBindin,mexNamedPipeBinidng.

NOTE – By default WCF Services do not expose Metadata exchange endpoint.Without knowing the information like address,Binding and contract it is very difficult to communicate with the service.WCF makes it easy to expose a MEX endpoint so that clients can communicate properly with services. The MEX endpoint can be exposed in code or in configuration.

The Link Enable Metadata of a Web Service  will help you in exposing/enabling the METADATA EXCHANGE point for a service using code and configuration files.

Thank You.

Categories: Uncategorized

ALL Link Resource information for DB,.NET ,BI and Many More..

Hello Friends

This is to inform you our mentalist series has launch new link resource website in which we will post link on Daily basis


Feature of Link Resource Website are as follow and links will contain following relate post

  • Inspirational
  • BI
  • DataBase
  • DotNet
  • Interesting Finds
  • Technical New
  • Hot Jobs
  • Carrier

For Example just have look at today posted link are as follows :


So Mentalist Series in Grow State having Following Website Now





Hope this is helpful and you will have a look or subscription to all of our blog.

Todays Quotes:

“I cannot cure myself of that most woeful of youth’s follies – thinking that those who care about us will care for the things that mean much to us.” — David Herbert Lawrence

Categories: Uncategorized