Introduction
In this article,i will teach you how to use SQL Server Comapact Edition 4.0 CTP1 with ASP.NET Dynamic Data website.
ASP.NET Dynamic Data provides a framework that enables you to quickly build a functional data-driven application, based on a LINQ to SQL or Entity Framework data model. Full CRUD (create, read, update, and delete) operations are supported. The ASP.NET Dynamic Data site includes filtering by foreign keys and Boolean fields; foreign keys are automatically converted to their friendly names. Smart validation is automatically available, which provides validation based on database constraints for nullable fields, data type, and field length.
Background
In order to under stand this article. You need to know about how to create ADO.NET Entity Data Model for Sql CE 4.0. I highly recommend you read my article 'ADO.NET Entity Data Model For SqlServer CE 4.0 CTP1' for more information about creating Entity Data Model for Sql CE 4.0 Database.
Solution:
Step 1:
Create a new ASP.NET Dynamic Data Entities WebApplication Project.
Step 2:
Create a new SQL CE 4 Database using Microsoft Web Matrix.
Step 3:
Create Entity Data Model for SQL CE 4 Database using EdmGen2.exe command line tool.
The tool can be downloaded from http://code.msdn.microsoft.com/EdmGen2
Open command prompt and Goto the folder containing EdmGen2.exe . Type the following commands in the order below
- EdmGen2 /ModelGen "Data Source= C:\SQLCEWebApp\App_Data\Database1.sdf" System.Data.SqlServerCe.4.0 Database1
- EdmGen2 /FromEdmx Database1.edmx
- EdmGen2 /Validate Database1.edmx
- EdmGen2 /ViewGen cs Database1.edmx
- EdmGen2 /CodeGen cs Database1.edmx
Step 4:
Add the SQL CE database and .EDMX file to project by select Add Exsting Item option.
Step 5:
Now open Global.asax file and look for a Commented line below
//DefaultModel.RegisterContext(typeof(YourDataContextType), new ContextConfiguration() { ScaffoldAllTables = false });
Step 6:
Now uncomment the above line and replace the YourDataContextType with the DataContext Class name from Database1.Designer.cs file and Change ScaffoldAllTables = true.
DefaultModel.RegisterContext(typeof(Database1Model.Database1Entities ), new ContextConfiguration() { ScaffoldAllTables = true});
Thats it!!!! Now you have a Full CRUD Website in a matter of seconds.
No comments:
Post a Comment