ADO.NET

1234
What to do when SaveChanges() fails?
Beginners often ask this question - "What course of action should I take when a call to SaveChanges() fails?" The answer may vary based on a given situation and requirement. This article discusses one way to deal with the errors and shows how to display descriptive error messages to the end user and then rollback the changes made to the model.
Posted On : 21 Jul 2014
Using Unit of Work Pattern in ASP.NET MVC and Entity Framework
Recently I wrote an article explaining the Repository Pattern and its use in ASP.NET MVC. This article builds on that article and explains another related design pattern - Unit of Work. The Unit of Work pattern states its intent like this - Maintains a list of objects affected by a business transaction and coordinates the writing out of changes and the resolution of concurrency problems.
Posted On : 15 Apr 2014
Using the Repository Pattern with ASP.NET MVC and Entity Framework
Data driven web applications need to have a neat strategy for data access. One of the important aspects of this strategy is the separation between the physical database, queries and other data access logic from the rest of the application. Repository pattern is a popular way to achieve such an isolation. This article discusses the basics of Repository pattern in the context of Entity Framework and ASP.NET MVC. It also illustrates how a repository can be built around your entities.
Posted On : 10 Apr 2014
Performing Asynchronous Operations Using Entity Framework
Asynchronous programming involves executing operations in the background so that the main thread can continue its own operations. This way the main thread can keep the user interface responsive while the background thread is processing the task at hand. .NET framework introduced the async and await keywords that simplify asynchronous programming. Entity Framework 6.0 also supports asynchronous operations for querying and saving of the data. This article discusses the basics of using asynchronous operations of Entity Framework in desktop as well as web applications.
Posted On : 18 Mar 2014
Working with Stored Procedures in Entity Framework - Part 2
In Part 1 of this two part series, you learned to map stored procedures for the INSERT, UPDATE and DELETE operations in the entity framework designer. EF also allows you call arbitrary stored procedures from your code. This part of the article discusses how.
Posted On : 12 Feb 2014
Working with Stored Procedures in Entity Framework - Part 1
By default entity framework generates SELECT, INSERT, UPDATE, DELETE queries to perform the respective operations on the database. At times, however, you may want to deviate from this default behavior and use stored procedures for these operations. Additionally, you may want to call arbitrary stored procedures to perform some task at hand. To that end this two part article explains how stored procedures can be dealt with in Entity Framework.
Posted On : 06 Feb 2014
Using Complex Types in Entity Framework
A database table represents your application data in row-column format. Although in many cases this row-column structure can be mapped directly to entities, at times you may need to reorganize the same. Consider, for example, the Customers table of Northwind database. The Customers table has Address, City, Region, Country and PostalCode columns representing the address of the company. The entity that represents this table might not be as "flat" as the table. For example, you may wish to have a property - Location - that is of class type and has properties such as Street, City, Region and PostalCode. Luckily, entity framework allows you to do so quite easily. The remainder of this article explains how.
Posted On : 15 Jan 2014
Executing Raw SQL Queries using Entity Framework
While working with Entity Framework developers mostly use LINQ to Entities to query database. However, at times you may need to execute raw queries against the database. A common scenario is when you wish to generate an SQL query dynamically. Luckily, EF allows you to execute raw queries easily. This article explains how that can be done.
Posted On : 09 Jan 2014
Dealing With Optimistic Concurrency in Entity Framework
When you update a database record with the entity values, the database values are overwritten by the entity values (default behavior). In a real world situation it is quite possible that database values might have got changed after selecting them for modification. In such cases, your update operation might be overwriting changes made by someone else. That is why it becomes important to detect if concurrency violation has occurred. You can then take some corrective action or at least inform the user about such a violation. To that end this article shows how to detect concurrency violation in EF and also the possible ways to deal with the situation.
Posted On : 30 Nov 2013
Understanding Database Initializers in Entity Framework Code First
Entity Framework Code First allows you to create data model classes prior to creating a database. When you run the application for the first time, a database is created for you on the fly based on the classes you created. Database initializers allow you to decide a strategy of database creation and seed data generation. Code First provides its own set of database initializer classes and also allows you to create your own. In this article you will learn to use the inbuilt database initializers in your application. You will also learn to create your own database initializers. Additionally, the article will illustrate how to populate a database with seed data during the initialization process.
Posted On : 11 Feb 2012
1234