Skip to main content

DataViewExtensionBase.BindToEF(String, String, EventHandler<LinqServerModeDataSourceSelectEventArgs>, EventHandler<ServerModeExceptionThrownEventArgs>) Method

Binds the DataView to a data source via the Entity Framework.

Namespace: DevExpress.Web.Mvc

Assembly: DevExpress.Web.Mvc5.v24.2.dll

Declaration

public DataViewExtensionBase BindToEF(
    string contextTypeName,
    string tableName,
    EventHandler<LinqServerModeDataSourceSelectEventArgs> selectingMethod,
    EventHandler<ServerModeExceptionThrownEventArgs> exceptionThrownMethod
)

Parameters

Name Type Description
contextTypeName String

A String object representing the DataContext type name.

tableName String

A String object specifying the table name.

selectingMethod EventHandler<LinqServerModeDataSourceSelectEventArgs>

A method to which selection logic is delegated.

exceptionThrownMethod EventHandler<ServerModeExceptionThrownEventArgs>

A delegate method that allows you to catch unhandled/CLR exceptions.

Returns

Type Description
DataViewExtensionBase

A DataViewExtensionBase object representing the DataView extension.

Remarks

Example

The code sample below demonstrates how to catch the internal exception thrown when binding the DataView to an EF data provider.

View code (Razor):

@Html.DevExpress().DataView(settings => {
    // DataView settings
}).BindToEF(string.Empty, string.Empty, (s, e) => {
    // Specify queryable source
    var dataContext = new MyProject.Models.MyDatabaseDataContext();
    e.QueryableSource = dataContext.Customers;
    e.KeyExpression = "Id";
}, (s, e) => {
    // Handle internal exception
    ViewContext.Writer.Write(e.Exception.Message + Environment.NewLine + e.Exception.StackTrace);
}).GetHtml()
See Also