NET data options to implement their models including: LINQ to Entities, LINQ to SQL, NHibernate, LLBLGen Pro, Sub Sonic, Wilson ORM, or just raw ADO. For our Nerd Dinner application we are going to use LINQ to SQL to create a simple model that corresponds fairly closely to our database design, and adds some custom validation logic and business rules.We will then implement a repository class that helps abstract away the data persistence implementation from the rest of the application, and enables us to easily unit test it.
In this article, we will see how to Add, Update and Delete objects in our conceptual model and push the changes to the underlying database.
The entire source code of this article can be downloaded over here.
This is step 3 of a free "Nerd Dinner" application tutorial that walks-through how to build a small, but complete, web application using ASP. Step 3 shows how to create a model that we can use to both query and update the database for our Nerd Dinner application. NET MVC 3, we recommend you follow the Getting Started With MVC 3 or MVC Music Store tutorials.
When Add Object() is called, a temporary Entity Key is generated and the Entity State is set to 'Added', as shown below: When context.
Save Changes() is called, EF 4.0 goes ahead and inserts the record into the database.