Click here to Skip to main content
13,505,979 members
Click here to Skip to main content
Add your own
alternative version


31 bookmarked
Posted 1 Feb 2009

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


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, update panel, and AJAX controls.


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:

<add name="DirectoryEntities" connectionString="metadata=res://*/DirectoryModel.csdl|
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" />

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.


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


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


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</em />
Click Create…
Record 2)
Name: Helen Clark
Content: Leader of New Zealand for 9 years
Helen, Leader NZ, New Zealander</em />
Click Create…

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


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"


loadingtext="[Loading categories...]" prompttext="
Please select a category" category="Category" />

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

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

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;
              ObjectQuery<category /> q = _directoryEntities.Category;
        result = q.Count(sub => sub.Name == name);               
    catch (Exception ex)
    return (result == 0) ? false : true;            

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

public void AddCategory(Category category)
         //some extra validation, logging here ....

    catch (Exception ex)


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


About the Author

Kurush Rastkar
Software Developer
New Zealand New Zealand
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralCascading Dropdown parent and child Pin
TahaKhan6-Feb-11 23:28
memberTahaKhan6-Feb-11 23:28 
GeneralRe: Cascading Dropdown parent and child Pin
Kurush Rastkar8-Feb-11 12:03
memberKurush Rastkar8-Feb-11 12:03 
GeneralRe: Cascading Dropdown parent and child Pin
darcy_ge5-May-11 19:44
memberdarcy_ge5-May-11 19:44 
GeneralGreat article Pin
Ian Bussières5-Jun-09 2:19
memberIan Bussières5-Jun-09 2:19 
GeneralDemo application Pin
TOANZ3-Feb-09 8:54
memberTOANZ3-Feb-09 8:54 
GeneralMy vote of 1 Pin
Rob Graham2-Feb-09 8:48
memberRob Graham2-Feb-09 8:48 

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

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

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180417.1 | Last Updated 1 Feb 2009
Article Copyright 2009 by Kurush Rastkar
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid