Thursday, April 28, 2011

How to create CRUD using Linq to Entity in ASP.NET 4?

In this project, I use Microsoft Visual C# 2010 Express Edition and Microsoft Visual Web Developer 2010 Express Edition
You need to create a class library project first. Then create a ADO.NET Entity Framework, then create a class and interface for each table or object.
Step 1 – Find and Click Start Then Find and Click Microsoft Visual C# 2010 Express
Step 2 – Find and Click New Project under File.
Step 3 – Find and Select Class Library then enter your chosen name for this class library project.
Step 4 – Click on Add new data Source under data.
Step 5 - Right Click and select Add Then new item.
Step 6 – Select ADO.NET Entity Data Model then type in your chosen name for your entity model.
Step 7 – Choose “Generate from Database” then click next.
Step 8 – Click on “New Connection ...” to create new connection. Then type in your chosen name for your connection string. Then click on next.

Step 9 – Choose your objects Then type in your chosen name for your model namespace.
Step 10 – All your chosen objects will be generated automatically.
To create a class for each tables, here are the steps:
Steps 1 - Right Click and select Add Then New Item. You need to add class.
Step 2 – Choose Class template, then type in your chosen class name.
Step 3 – To create interface, just repeat the steps in creating a class.
Here are the samples codes for both interface and class file:
 You may go to my other blog

No comments:

Post a Comment