![]() |
Web Development »
ASP.NET »
General
Intermediate
License: The Code Project Open License (CPOL)
AJAX, WCF, LINQ to Entities demo applicationBy Kurush RastkarUsing most of the recent technologies in one application |
C#, .NET (.NET3.5), Vista, SQL-Server (SQL2005), Visual-Studio (VS2008), WCF, LINQ, Dev
|
||||||||||
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
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…
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.
VS 2008, Framework 3.5 , SQL server.
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=" Data Source=localhost;Initial Catalog=Directory; Persist Security Info=True; User ID=USEREID;Password=YOURPASSWORD;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" /> </connectionStrings>
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.
There are only four tables which are involved in this application.
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.
Once you have done the configuration and started running the application you will be presented with the following 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
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.
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>
Example code1: This method checks whether the category name, which is passed as a parameter, already being used.
private DirectoryEntities _directoryEntities = newDirectoryEntities(); ... public bool DoesCategoryNameExist(string name) { int result = 0; try { ObjectQuery 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: } }
| You must Sign In to use this message board. | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+PgUp/PgDown to switch pages.
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 1 Feb 2009 Editor: Sean Ewington |
Copyright 2009 by Kurush Rastkar Everything else Copyright © CodeProject, 1999-2010 Web17 | Advertise on the Code Project |