October 2008 - Posts

Code Generation Using Repository Factory!!

From the time, I've become familiar with Repository Factory, I've been continuously using it to generate my data access layer code. It has some few steps that i normally follow to successfully generate my data layer which contains business entities, stored procedures and repository classes. For this, i have installed DataAccessGuidancePackage.msi.

After installing guidance package, i create a class library project from my solution explorer. And then I choose Guidance Package Manager submenu from Tools mainmenu.

 

Then, I enable the guidance package manager and I select the Repository Factory CheckBox.

Now, I'm ready for generating code.Then, I right click the project and specify its reposibilities to be by checking all options as shown below.

After that, I add the database connection and it will generate app.config file for me.

Then, I select "Create business entities from database" option as shown above and select the tables for which i need to generate entities as below. It will generate properties for each field and class for each table.

 

Likewise, following the same process as above, I select the tables this time, for which I have to generate CRUD methods and, it'll generate SQL scripts for me which i run in MSSQL database.

 

Finally, most important is that, I select option to create repostiory classes. It will generate a whole bunch of classes within a minute. If I've to write those code, it would take weeks for me, though my typing speed is not so poor.

 It has helped me very much. Now, I can use this repository classes to directly bind data with data controls in presentation layer or just use in business object layer. Why not try yourself ..?

 

 

 

 

Posted by Padam Raj Gurung with 2 comment(s)
Filed under:

My First MVC Test Application!!

This is my first mvc test application and it is very  simple to startwith. I have heard and read about MVC in blogs and websites two or more times, but I still haven't  tested it. But, today, I find it quite interesting and efficient to my previous asp.net techniques. I have tested this application in CTP 3 release of MVC.

First of all, I created a MVC web application from the New project sub menu.

 

Then, I created table named task and generated its LinqToSql O/R mapping class.

 

After that, I wrote public functions in the Home controller class.

After that, I created 'Index' view

 

and 'Create' view.

 

Finally, When I have run my code, it worked excellent.

Download source code: FirstMVCApp.zip

 

Posted by Padam Raj Gurung with 1 comment(s)
Filed under:

DataTable has lots of cool features!!

Many of us proabably haven't used the coolest features provided in DataTable. I was also unknown to its features previously. I came across this features one day, when i just roaming in search engines.

Some features, I like most are listed below.

1. I can directly load the SqlDataReader by using the load method of datatable. So I don't need to use data adapter any more.

e.g. DataTable dt = new DataTable();

dt.Load(sqlDataReader);

2.  It can be used directly as a datasource as well. e.g.  dt.CreateDataReader();

3. It has functions like ReadXML, WriteXML, ReadXmlSchema, WriteXmlSchema...to work with XML file directly.

4. I can use FindBy<Primarykey> method to get the particular data row.

e.g ProductDataRow dr = dt.FindByProductID(proID); //search

5. I even can select filtered datarows.. sort by fieldname.

e.g. DataRows[] rows=  dt.Select("Price>100", "ProductName");//filter and sort

6. I even can compute sum, average...without iterating datatable.

e.g. decimal totalAmount = dt.Compute("Sum(ProductPrice)",String.Empty);//sum

 

Ya...very nice features.

These are most common functions I use and there are lots more...They are type safe, and has user friendly functionalities like sorting, filtering, searching etc. I really enjoy using these functionalities of Typed dataset and datatable provided by ADO.NET.

 

Posted by Padam Raj Gurung with no comments
Filed under:

System.Transactions best for SQL 2005!!

In .net framework 2.0, a new namespace has been introduced, called System.Transactions. I have been able to greatly reduce my code for doing SQL transaction.

The code goes like this.

 

Using System.Transactions;

using (TransactionScope scope = new TransactionScope())

{

    using(SqlConnection conn = new SqlConnection(connString))

   {

       SqlCommand cmdInsert = conn.CreateCommand();

       cmdInsert.CommandText="INSERT INTO...";

       SqlCommand cmdUpdate = conn.CreateCommand();

       cmdUpdate.CommandText="UPDATE .....";

      cmdInsert.ExecuteNonQuery();

      cmdUpdate.ExecuteNonQuery();


   }

   scope.Complete();


}

Whenever I've to work for SQL 2005, I don't miss to use TransactionScope. Its short and simple.



 

Posted by Padam Raj Gurung with no comments
Filed under:

My web page lost intellisense!!

I was in much poblem from last few days. When I use masterpage and visual studio 2005 with ajax enable website. Anything that goes inside content template of update panel lost intellisence. But when it was viewed in browser, it worked well. I was in great trouble to troubleshoot this problem. Have you ever face this kind of problem?

May or maynot....After googling a lot, finally, I got soution from Scott Guthrie.

He has  posted two solutions for this:

1. First, you kept open your master page in solution when you are working with other pages derived from this master page, this gives intellisence to your webpage. But this is not best solution.

2. Second is that, you should install VS 2005 SP1, this problem will be automatically solved.

 

Finally, I got solution. Thanks Scott.

 

 

Posted by Padam Raj Gurung with 1 comment(s)
Filed under: ,