Click here to Skip to main content
Click here to Skip to main content
Go to top

AJAX, WCF, LINQ to Entities demo application

, 1 Feb 2009
Rate this:
Please Sign up or sign in to vote.
Using most of the recent technologies in one application

Table of Content

  • Introduction
  • Architecture and Technology
  • Pre-requisites
  • Installation guide
  • Database tables
  • Purpose of the application
  • How to use ( instruction )
  • Code

Introduction

I started this project for fun and to get some experience using most of the recent technologies in one application. I have enjoyed developing it and hope you enjoy reading about it and using it…

Architecture and Technology

The Directory project is a simple application which has been designed using n-tire application architecture (see figure below). The application was developed in the .NET platform utilizing C#, Framework 3.5, LINQ to Entity with lambda expression, WCF, asp.net update panel, and AJAX controls.



Pre-requisites

VS 2008, Framework 3.5 , SQL server.

Installation Guide

  • Unzip the attached file
  • Create a database in SQL server called “Directory”
  • Run the DirecotryDatabaseTables.sql against this database to create all the required tables. You can find this file in the attached zip in the folder called DatabaseTables
  • Open the IIS manager (open Run and type in “inetmgr” or the hard way!! Go to control panel -> Administration Tool -> IIS Manager if you are running Vista! Otherwise good luck finding it)
  • Create a new Application Pool or a Virtual Directory called “Directory” and point that to the Web folder of the application
  • Open the application in VS 2008 and update the connection string in the web.config
    • Update data source ( if database is not in your local pc )
    • User Id and password

Connection string in webconfig file:

<connectionStrings>
<add name="DirectoryEntities" connectionString="metadata=res://*/DirectoryModel.csdl|
res://*/DirectoryModel.ssdl|res://*/DirectoryModel.msl;
provider=System.Data.SqlClient;
provider connection string=&quot;
Data Source=localhost;Initial Catalog=Directory;
Persist Security Info=True;
User ID=USEREID;Password=YOURPASSWORD;MultipleActiveResultSets=True&quot;" 
providerName="System.Data.EntityClient" />
</connectionStrings>

Purpose of the application

It allows the user to create different categories of THINGS eg: contacts, books, code and etc and store them in the database. It also provides two different search engines that can be used to retrieve the stored information and display them on screen.

Database structure

There are only four tables which are involved in this application.

How to use:

To understand how this application works I would like to suggest you follow the example below. These instructions will help you to create some records in the database and let you use the search screen to retrieve those records and display them on the screen.

Main screen

Once you have done the configuration and started running the application you will be presented with the following screen:

Maintenance screen:

Open this window by clicking on the OPEN FOLDER icon from the main page.


Category:

In the first tab enter a name for the new category and click Create. The description is optional.
Enter the following information: Famous People

Subcategory:

Choose the second tab (Subcategory) - and enter a name for subcategory and click Create. The description is optional.
Enter the following information: New Zealand

Subject:

Choose the last tab (Subject) and enter the following information:
Record 1)
Name: Peter Jackson
Content: Director of the Lord of the Rings
peter, Jackson, Peter Jackson, New Zealander
Click Create…
Record 2)
Name: Helen Clark
Content: Leader of New Zealand for 9 years
Helen, Leader NZ, New Zealander
Click Create…

Close the maintenance window. Now you can search for above information using the search engine on the main screen.

Code:

You can browse the source code in the attach zip file but I would like to point out some of interesting and important sections of this application.

AJAX controls

In the main page I used the AJAX CascadingDropDown control in conjunction with WCF to load the Categories.

   
 
<dropdownlist id="DropDownLisCategory" autopostback="true" onselectedindexchanged="
OnSelectDropDownCategoryChanged" cssclass="dropdownSmall" runat="server" />

<cascadingdropdown id="CascadingDropDown1" runat="server" 
targetcontrolid="DropDownLisCategory" servicemethod="GetAllCategoriesIdAndName"
 servicepath="~/Services/DirectoryService.svc" 
loadingtext="[Loading categories...]" prompttext="
Please select a category" category="Category" />

WCF
Following code shows how to include the WCF to the script manager tag.

<asp:ScriptManager ID="scriptMgr" runat="server">
        <Services>
            <asp:ServiceReference Path="~/Services/DirectoryService.svc" />
        </Services>
    </asp:ScriptManager>

The WCF files in this project:

LINQ to Entity
Certainly the LINQ is one of the most interesting technologies around but it would be more popular if it worked with Oracle or …

Example code1: This method checks whether the category name, which is passed as a parameter, already being used.

 private DirectoryEntities _directoryEntities = new <cod />DirectoryEntities();

...
public bool DoesCategoryNameExist(string name)
{
     int result = 0;
    try
    {            
              ObjectQuery<category /> q = _directoryEntities.Category;
        result = q.Count(sub => sub.Name == name);               
    }
    catch (Exception ex)
    {
        //TODO:
    }
    return (result == 0) ? false : true;            
 }

Example code2: The mehod below create a new category in the database.

 
public void AddCategory(Category category)
{
    try
    {
         //some extra validation, logging here ....
                _directoryEntities.AddToCategory(category);
                _directoryEntities.SaveChanges(true);

     }
    catch (Exception ex)
    {
        //ToDO:
                
    }
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Kurush Rastkar
Software Developer
New Zealand New Zealand
No Biography provided

Comments and Discussions

 
GeneralCascading Dropdown parent and child PinmemberTahaKhan6-Feb-11 23:28 
GeneralRe: Cascading Dropdown parent and child PinmemberKurush Rastkar8-Feb-11 12:03 
GeneralRe: Cascading Dropdown parent and child Pinmemberdarcy_ge5-May-11 19:44 
GeneralGreat article PinmemberIan Bussières5-Jun-09 2:19 
GeneralDemo application PinmemberTOANZ3-Feb-09 8:54 
GeneralMy vote of 1 PinmemberRob Graham2-Feb-09 8:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 1 Feb 2009
Article Copyright 2009 by Kurush Rastkar
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid