Creating a New Context For Each CRUD Operation
This article is relevant to entity models that utilize the deprecated Visual Studio integration of Telerik Data Access. The current documentation of the Data Access framework is available here.
Another approach is to execute CRUD operations by creating and disposing the context whenever that is needed.
For example:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load( object sender, EventArgs e )
{
using ( EntitiesModel dbContext = new EntitiesModel() )
{
List<Category> categories = dbContext.Categories.ToList();
}
}
}
Public Class _Default
Inherits Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Using dbContext As New EntitiesModel()
Dim categories As List(Of Category) = dbContext.Categories.ToList()
End Using
End Sub
End Class