Creating Understanding and Educating Programmers, Developers and Technical Communities, one post at a time.

Tuesday, June 9, 2009

Data Access Layer Design Considerations

To help ensure that data access in your application is optimized for performance, there are several issues that you must consider and a number of decisions that you must make at design time:

  • Design your data access layer based on how the data is used.

  • Cache data to avoid unnecessary work.

  • Connect by using service accounts.

  • Acquire late, release early.

  • Close disposable resources.

  • Reduce round trips.

  • Return only the data you need.

  • Use Windows authentication.

  • Choose the appropriate transaction type.

  • Use stored procedures.

  • Prioritize performance, maintainability, and productivity when you choose how to pass data across layers.

  • Consider how to handle exceptions.

  • Use appropriate normalization.



Reference: http://msdn.microsoft.com/en-us/library/ms998569.aspx

Tuesday, June 2, 2009

Extension Methods

Extension Methods enable you to "add" methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type. Extension methods are a special kind of static method, but they are called as if they were instance methods on the extended type. For client code written in C# and Visual Basic, there is no apparent difference between calling an extension method and the methods that are actually defined in a type.

I found a very good tutorial on Extension Method.

Friday, May 29, 2009

[Quick Tip] Session

During the development of Asp.Net application, developer don't need to instantiate any session. Session is automatically instantiated, you need to use them according to your requirement. Here, I am going to show you one simple example.

DataTable dt = new DataTable();

// what ever the table you want to put in dt

// assign dt value into session variable, make sure it is unique name,
// I have given dtSessionVariable as session variable name.
Session["dtSessionVariable"] = dt;


// To retrieve it from session, it require casting back to original type
DataTable dt = (DataTable)Session["dtSessionVariable"];

Monday, May 18, 2009

Friday, May 15, 2009

Structure

Structure is a lightweight class in C#. The following list details the differences between structures and classes.

Structure
  • implicity inherits from System.ValueType (always reside on stack)
  • are sealed and can not be inherited, and also cannot inherit classes and other structures
  • The default constructor of a structure cannot be replaced by a custom constructor.
  • Custom constructors of a structure must fully initialize the value of the structure.
  • Dont have a destructor
  • Field initialization is not allowed. Const members of a structure can be initialized.

Thursday, May 14, 2009

Global.asax

The Global.asax file(the ASP.NET application file) contains code for responding to application-level and session-level events raised by ASP.NET or by HTTP modules.

By default, the ASP.NET Framework maintains a pool of HttpApplication objects to service incoming page requests. A separate HttpApplication instance is assigned to each request.

If you prefer, you can create a custom HttpApplication class. That way, an instance of your custom class is assigned to each page request.

You can create custom properties in your derived class. These properties can be accessed from any page, control, or component. You also can handle any application events in your custom HttpApplication class.

You create a custom HttpApplication class by creating a special file named Global.asax in the root of your application. Following are few more detail about it.

  • It is optional file.
  • It must be located in the root directory. (file located in sub-directory is simply ignored)
  • Only one global.asax file per application. (you can not have more than one for an application.)
Example:

public class Global: System.Web.HttpApplication
{
//It is derived from HttpApplication base class

protected void Application_Start(Object sender, EventArgs e)
{
//lush(good) code
}
}

Sunday, May 10, 2009

void pointer

Pointer to void (void *) is a generic pointer capable of representing any pointer type. All pointer types can be assigned a pointer to void without casting. However, a pointer to void cannot be assigned directly to a pointer of another type - the void pointer must first be cast to proper pointer type.

A void * pointer can not be dereferenced.