Wednesday, December 24, 2008

Microsoft ASP.NET MVC Frame Work And LINQ to Entity

I have started to learn Microsoft ASP.NET MVC framework and LINQ to entity. I thought to create working example with above. 

I am not going to explain what ASP.NET MVS is and What LINQ To Entities are, But I will explain how I have do a order form with using those two.

You can refere following urls to find out more on ASP.NET MVC and LINQ to SQL.






This example will show how to create a Order form with ASP.NET MVC and Linq To Entity.

1.  Starting Fresh ASP.NET MVC Project.

1. You need to install ASP.NET MVC Framework (Beta).  http://www.asp.net/mvc
    Create a MVC Project by Selecting "ASP.NET MVC Web Application"


Solution Explorer will look like as follows.

The freash MVC project will have pages to login, change password etc. 

2.  Database Design



Table Name                                   Description
------------                                    -----------------------------------------
Item Item Master Table
Customer Customer Master Table
Order Order Header Table
OrderDetail Order Detail Table
Tempdata This table will use to save orders temporary until finished adding new Items. Because order can have maney Items.

3.  Creating Business Layer (dll) with LINQ to Entity

Add  a new Project (Type Class Library)  names "LM.Core". In this project will handle business layer functionalities.


Solution explorer after adding "LM.Core" Project.

In "LM.Core" there will be a Class called "Class1" (Class1.cs). Delete "Class1.cs" from "LM.Core", we can add necessory classes later as required.



No we can add ADO.NET Entity Model. Right click on "LM.Core" Add-> New Item.
Item name will be LMModel.



A wizard will begin just after click "Add" Button. Wizard steps will be as follows.

Step 1



Step 2 - Choose Data Connection




Step 3 - Select Tables



Solution Explorer after adding Entity Model to "LM.Core" Project.



LMModel.edmx will show following diagram.

We can extend the Linq to entity classes to add our own methods as follows.

Extending Item Class

Add a new class to LM.Core named Item (Item.cs). I have added twi new methods "GetItem()" and "GetByID()"



Customer, Order, OrderDetail and TempData classes need to be extended as required.


4.  Create Order Form

Order Form UI need to be created on Application project. According to ASP.NET MVC framework we need to add Controller and views for the order.

Add new Item named OrderController to the Controllers Folder located in application project.



and also add another class called BaseController to the Controller folder.

BaseController is inherited from "System.Web.Mvc.Controller"



Originally OrderController class wil inherited from "System.Web.Mvc.Controller", change it to "BaseController" (which we created).




Sorry .........., Still Updating ........................
Even though I am still updating this blog,  you can help me to improve the quality of this blog by providing your valuble comments. 


2 comments:

Sudath said...

Good job Dinesh... keep it up..

Unknown said...

Hello Dinesh, I would like to say that people who want promotion in their job, they can get certification in Microsoft technology as it is one of the most demanded courses in MNCs.

Regards,
Crish Watson
Pass Microsoft Certification Without Taking Exam