DbContextDataSource is a DataSource Control for ASP.Net WebForms Data-bound controls, specially .Net 4.0. The control allows CRUD operations with Entityframework 5.0 Code First DbContext. The control Extends the LinqDataSource cababilities to Insert, Update, Delete the Table selected in the Control with a context class Drived from DbContext.
When choosing the Code First approach for modeling the database, we loose the ability to work with EntityDataSource, as it only supports ObjectContext.
We can use the LinqDataSource with DbContext for all the Read Operations, including Ordering, Sotring, and Grouping. But LinqDataSource cannot make Insert, Update, Delete Operations else with the Data Context of the Linq to SQL.
The DbContextDataSource extends the LinqDataSource, which itself extends the generic ContextDataSource, andQueryableDataSource. The DbContextDataSource replaces all the methods that depends on Linq to SQL data contexts with code that targets EF 5.0 DbContext.
The DbContextDataSource specially targets .Net 4.0 ASP.Net Web Forms, where we depend on data sources for data binding.
As of ASP.Net 4.5, DataControls allows for Model Binding where the Model and all CRUD operations directly on the control definition without the need for any Data Source controls. This allows for the use of data repositories which applies the concepts of separation of concerns.
The package contains EFDataSources.dll assembly which will be added to the bin folder. Then in Web Form Page add the registration tag for the assembly:
<%@ Register Assembly="EFDataSources" Namespace="EFDataSources" TagPrefix="cc1" %>
Then declare the data source as if it was LinqDataSource, you will have the same context menu to Configure the data source with the configuration wizard. Also the context menu will allow you to Enable Insert, Update, and Delete Operations, but for the EF 5.0 DbContext!!
<cc1:DbContextDataSource runat="server" ID="ProductsDataSource" ContextTypeName = "OrdersContext"
TableName="Products" Where="Price < 1000" EntityTypeName="" EnableInsert="True" >
</cc1:DbContextDataSource>