LinqDataSourceContextEventArgs 类

定义

ContextCreating 事件提供数据。Provides data for the ContextCreating event.

public ref class LinqDataSourceContextEventArgs : EventArgs
public class LinqDataSourceContextEventArgs : EventArgs
type LinqDataSourceContextEventArgs = class
    inherit EventArgs
Public Class LinqDataSourceContextEventArgs
Inherits EventArgs
继承
LinqDataSourceContextEventArgs

示例

下面的示例演示如何通过在ContextCreating事件的事件处理程序中调用非参数构造函数来创建数据上下文对象。The following example shows how to create the data context object by calling a non-parameterless constructor in an event handler for the ContextCreating event. 该代码将自定义对象分配给ObjectInstance属性。The code assigns the custom object to the ObjectInstance property.

protected void LinqDataSource_ContextCreating(object sender, LinqDataSourceContextEventArgs e)
{
    e.ObjectInstance = new ExampleDataContext(ConfigurationManager.ConnectionStrings["ExampleConnectionString"].ConnectionString);
}
Protected Sub LinqDataSource_ContextCreating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LinqDataSourceContextEventArgs)
    e.ObjectInstance = New ExampleDataContext(ConfigurationManager.ConnectionStrings("ExampleConnectionString").ConnectionString)
End Sub

注解

默认情况下, LinqDataSource该控件创建ContextTypeName在属性中指定的类型的实例。By default, the LinqDataSource control creates an instance of the type that is specified in the ContextTypeName property. LinqDataSource控件调用数据上下文对象的无参数构造函数来创建对象的实例。The LinqDataSource control calls the parameterless constructor of the data context object to create an instance of the object.

可以通过处理ContextCreating事件来手动创建数据上下文对象。You can manually create the data context object by handling the ContextCreating event. 如果要使用非参数构造函数, 请执行此操作。You do this if you want to use a non-parameterless constructor.

如果要创建的数据ContextCreating上下文对象不同于在ContextTypeName属性中指定的对象, 也可以处理该事件。You can also handle the ContextCreating event if you want to create a data context object that is different from the one specified in the ContextTypeName property. 在这种情况下, 将ObjectInstance属性设置为创建的对象。In that case, you set the ObjectInstance property to the object you created. LinqDataSource控件将使用您为选择数据而创建的对象。The LinqDataSource control will use the object you have created for selecting the data. 在更新、插入或删除数据时, 必须将ObjectInstance属性设置为DataContext从类派生的对象。When you are updating, inserting, or deleting data, you must set the ObjectInstance property to an object that derives from the DataContext class.

构造函数

LinqDataSourceContextEventArgs()

初始化 LinqDataSourceContextEventArgs 类的新实例。Initializes a new instance of the LinqDataSourceContextEventArgs class.

LinqDataSourceContextEventArgs(DataSourceOperation)

为指定的数据操作初始化 LinqDataSourceContextEventArgs 类的新实例。Initializes a new instance of the LinqDataSourceContextEventArgs class for the specified data operation.

属性

ObjectInstance

获取或设置要创建的数据上下文对象。Gets or sets the data context object to create.

Operation

获取正在执行的数据操作。Gets the data operation that is being performed.

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

适用于