Data Access has been discontinued. Please refer to this page for more information.

CRUD Operations - API Differences

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.

The purpose of this topic is to illustrate you the most important API differences between Telerik Data Access and Entity Framework regarding the CRUD operations. After converting your project from Entity Framework to Telerik Data Access, it may be no longer buildable. In most of the cases the reason for this will be the various API differences.

Creating New Objects

In Telerik Data Access, the only way to create and initialize new objects is to use the standard .NET pattern:

Customer customer = new Customer
    {
       Address = "Sofia",
       City = "Sofia",
       Country = "Bulgaria"
    };
Dim _customer As Customer = New Customer With _
    { _
        .Address = "Sofia", _ 
        .City = "Sofia", _
        .Country = "Bulgaria" _
    }

For example, the following Entity Framework constructions can not be achieved with the Telerik Data Access API:

  • dbContext.Customers.CreateObject();
  • Customer customer = Customer.CreateCustomer( /Required parameters/);

Inserting Objects

To add a new object in Telerik Data Access, you need to use the Add method of the context. For more information, please refer to How to: Insert Objects.

dbContext.Add(customer);
dbContext.Add(customer)

For example, you will need to replace manually the following Entity Framework API calls:

  • dbContext.AddObject("Customer", customer);
  • dbContext.AddToCustomers(customer);
  • dbContext.Customers.AddObject(customer);

Deleting Objects

In Telerik Data Access, you delete objects by invoking the Delete method of the OpenAccessContext instance. You need to replace the corresponding Entity Framework method - DeleteObject. For more information, please refer to How to: Delete Objects.

dbContext.Delete(customer);
dbContext.Delete(customer)

Saving Changes

In Entity Framework and Telerik Data Access you save changes to the underlying database by invoking the SaveChanges method of the DataContext/OpenAccessContext instance. For more information, please refer to How to: Save Changes.

using ( EntitiesModel dbContext = new EntitiesModel() )
{
   dbContext.SaveChanges();
}
Using dbContext As New EntitiesModel()
 dbContext.SaveChanges()
End Using

Fetch Plans

Telerik Data Access supports Fetch Plans. FetchPlans allow you to load references and fields in addition to what needs to be loaded by a single operation with the goal to eliminate the additional round-trips to the database server. In Entity Framework, when you know the exact shape of the graph of related entities that your application requires, you can use the Include method to define a query path that controls which related entities to return as part of the initial query:

IQueryable<Category> query = 
    from category in dbContext.Categories.Include( "Products" )
    select category;
Dim query As IQueryable(Of Category) = _
    From category In dbContext.Categories.Include("Products")
    Select category

In Telerik Data Access, you have the same Include method. However, the syntax is slightly different:

IQueryable<Category> query = 
    from category in dbContext.Categories.Include( c=>c.Products )
    select category;
Dim query As IQueryable(Of Category) = _
    From category In dbContext.Categories.Include(Function(c) c.Products)
    Select category

References

For further reference, see the CRUD Operations section.