Archive for the 'ASP.NET' Category
ASP.NET 3.5 Entity Framework
Introduction
This post explains how to create a Model from the database using ASP.NET Entity Framework. Using Entity Framework you can define the flexible mapping to existing relational schema.
Here I have created a new console application to explain the ASP.NET Entity Framework. You need to install the VS 2008 SP1 to work with the ASP.NET Entity Framework.
1. Right click the Project and Create a Data Model for database by selecting
Add New item option. It looks like the following screenshot.
2. It prompts you to select the option for Model from dialogue box
3. Specify the Database Connection and it generates the Entity Framework
connection string which will save in the web.config file.
The metadata section in the connection string specifies how to interact the objects with the database. csdl describes the model. ssdl describes the database model and msl describes the mapping between model and database model. Next part in the connection string is database provider here we are using SQL provider and last part is connection string for the provider.
4. Choose the database objects to build the model.
From the above dialogue box we can choose desired tables, views and stored procedures.
5. Now Entity Frame work generates the default model and entities in the
Project.
Navigation properties in the above model describes mapping between the models.
6. Establish the object context to interact with entities.
7. We can see the results by executing the project
Conclusion
What we have done is we have taken a existing database to generate the Entity Framework model then we used object context to show the data from the database.
1 commentASP.NET 3.5 Nested Master Pages
Introduction
This post explains the improved designer for creating Nested Master pages in visual studio 2008 and ASP.NET 3.5. Nested Master pages are used when you are build a hierarchy of templates for your web site.
For Example your Enterprise may have the corporate style header and each of your department in your organization may have different templates styles there you can use nested master pages for designing the templates.
You did have this feature in ASP.NET 2.0 but you were not able to work out with the visuals in the designer.
Working with Nested Master pages in VS 2008 and ASP.NET 3.5 in a sample
1. Create a New Web site in VS 2008 File, New Web site it looks like the following screen shot
2. Create a Nested Master page to link the above master page by right clicking the web site and select add new item option dialogue box will appear from there select the NestedMasterPage template.
NestedMasterPages allows you to link masterpages together.
Select the Master page and click ok it will link to the selected masterpage.
We have created the above NestedMasterPage for a Department. The new feature that you need to observe is you are able to see the visuals in designer where you can edit the content in NestedMasterPage and you can view the results immediately in designer.
3. Now we are going to create a content page for this NestedMasterPage. Right click the project and select Add New Item the following dialogue box will appear
Instead of selecting a Web Form, we have new option Web Content form template in VS 2008 select this template for creating the content page for the NestedMasterPage.
4. The NestedContentPage will looks like the following
This is basically representing the what we are going to see in browser by having the Global MasterPage, NestedMastePage and Content Page which really increasing the developer integrated design experience.
1 commentASP.NET Dynamic Data Site Fields Rendering
Introduction
Dynamic Data uses Data context objects and metadata model to present the information using templates. This post speaks about how we can control the display of dynamic data. Some times we want to change the default rendering of the templates.
How we can change the Fields Rendering
1. Let us take sample and change the Field Rendering
From the above sample we are going to change the Display format of the Publish Date field.
2. Open the NorthWind.dbml file from the Dynamic Data Web site project, if you view the code behind file which is automatically generated by the Dynamic Data Web Site Project. It looks like in the following figure
3. We are not editing the above class because it is generated from the Database meta model. We are going to create new partial class with name Book in the App_code folder. It looks like in the following figure.
We added the MetadataType attribute to the book class which is of the type BookMetadata class. BookMetadata class defines the DisplayFormat of the publishdate field.
We have used the DisplayFormat attribute which defines the dateformat with nameparameters.
4. Run the project to see the Result in the Dynamic Data Web site
1 commentASP.NET Dynamic Data Inline Editing
Introduction
This post explains how to edit the data inline in grid view control. I explained the overview on ASP.NET Dynamic Data and creating a simple Dynamic Data Web site using Scaffolding.
How to edit the inline data in Grid view
1. Open the Dynamic Data Web site that you have created in Dynamic Data Web site using Scaffolding.
2. Open the Global.asax file it looks like
The Default route will look like above highlighted area. It took the table as database table name and action is one of List,Details,Edit or Insert. Comment the default route which shown above in the screen shot.
3. There are some routing statements put in the comments below the default route, we have to un comment the section.
From the above new routing statement observe that instead action it is having ListDetails page for Action List and Details. So Same page is using for listing the results and editing the data.
4. You can find the ListDetails.aspx page under PageTemplates in the Dynamic Data Web Site.
5. When execute the project we will see the following screen which is ready for inline editing when you are updating the record.
2 commentsCreating a Dynamic Data web site using Scaffolding
Introduction
This post explains how to create a basic Web application that uses ASP.NET Dynamic Data. ASP.NET Dynamic Data provides the Web application scaffolding that enables you to build rich data-driven Web applications.
scaffolding is mechanism that enhance the functionality of the existing ASP.NET Framework by adding the ability to dynamically display pages based on the data model of the database.
Creating a Dynamic Data Web site
We can use web site template to create a Dynamic Data Web Site.
The following steps explains the procedure
- Start Visual Studio 2008.
- Go to File menu, click New Web Site, New web site dialogue box is displayed.
3. Select the Dynamic Data Web Site Template from the above dialogue box.
4. In the Location box type the name for the web site and click ok.
Adding the Data to Web site
Add a database to the project and create the database model
To Add the database file to project.
1. In solution explorer, Right click the App_Data folder and click Add Existing Item.
2. Enter the AdventureWorks_Data.mdf name location file in location box.
The next step is create the Data model
To create the data model using LINQ to SQL
1. Right click the solution explorer and then click Add New Item.
2. Click Add the following dialogue will appear
Object Relational Designer is displayed
In the O/R Designer , Click the Server Explorer link
3. From Database Explorer, under data connections, expand the database file node and then table node.
4. Drag all tables into the O\R designer. Each table represented as entity.
Register the data context
1. Open the Global.asax file.
2. model.RegisterContext(typeof(AdventureWorksDataContext),
new ContextConfiguration() { ScaffoldAllTables = true });
3. The above line in Global.asax file registers the LINQ to SQL data context for Dynamic data web site.
Testing Dynamic Data web site
1. In Solution explorer, right-click the Default.aspx page, and then click on view in browser.
2. The following screen shows the browse page
3. Using the above site you can add/edit/delete the data in a particular table.
3 commentsASP.NET Dynamic Data Overview
Introduction
ASP.NET Dynamic Data provides the Web application scaffolding that enables you to build rich data-driven Web applications. scaffolding is mechanism that enhance the functionality of the existing ASP.NET Framework by adding the ability to dynamically display pages based on the data model of the database.
This mechanism generates the page based on the default templates, while enabling the complete customization. Customization is allowed at table as well as application level. The dynamic data fields are user controls that render standard data field types.
The sample web site application to develop using ASP.NET Dynamic data
Features
provides the following features to support the rapid development of data-driven web applications:
- ORM Object-Relational Mapping designer which generates the classes based on the data model.
- Page Templates provides the default view of data.
- Dynamic data fields for rendering the individual data types.
- Built-in data validation based on the database schema.
- Dynamic Data configuration settings that you can customize in the web.config file.
- Supports the ASP.NET Datacontrols for customization.
Background
ASP.NET Dynamic Data renders the data fields from the database metadata It also provides the capability to add information to metadata through data model which is used for custom validation.
In Visual Studio 2008, you can use the LINQ to SQL classes template to generate the data model classes. After generating the classes you can see them in App_Code folder.
System.Web.DynamicData Contains classes that provide the core functionality for ASP.NET Dynamic Data. It also provides extensibility features to customize dynamic data behavior.
2 commentsWeb 2.0 Basics
Introduction
1. Web 2.0 is a term coined by O’Reilly Media.
2. Web 2.0 is a second generation of internet based services.
3. Web 2.0 hints a improved form of world wide web.
No commentsASP.NET Enhancements
The following are the ASP.NET enhancements in .NET Framework 3.5
1. Development support for AJAX-enabled Websites.
2. Support provided for LINQ (Language-Integrated Query).
3. Full IntelliSense support in Visual Studio 2008 for working with JavaScript.
4. ASP.NET Merge tool (Aspnet_merge.exe) allows you to combine and manage the assemblies that are
created by pre-compilation tool Aspnet_compiler.exe.This merge tool builds the single assemblies
for the website. Earlier add-on was released for Visual studio 2005 to build the assembly.
5. Web application project model supported in this version. This feature easily allows us to migrate the
visual studio 2003 websites to the current version
6. One instance of Web application can target the .net framework version 2.0,3.0 and 3.5
7. Support has been given to ASP.NET Ajax extender controls
8. WCF Services can be consumed in the web project.
9. Intellisense Support is provided for LINQ.
10. AJAX enabled sites can access the web services and WCF services.
1 comment