LinqDataSourceContextEventArgs Class (System.Web.UI.WebControls)

Switch View :
ScriptFree
.NET Framework Class Library
LinqDataSourceContextEventArgs Class

Provides data for the ContextCreating event.

Inheritance Hierarchy

System.Object
  System.EventArgs
    System.Web.UI.WebControls.LinqDataSourceContextEventArgs

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web.Extensions (in System.Web.Extensions.dll)
Syntax

Visual Basic
Public Class LinqDataSourceContextEventArgs _
	Inherits EventArgs
C#
public class LinqDataSourceContextEventArgs : EventArgs
Visual C++
public ref class LinqDataSourceContextEventArgs : public EventArgs
F#
type LinqDataSourceContextEventArgs =  
    class
        inherit EventArgs
    end

The LinqDataSourceContextEventArgs type exposes the following members.

Constructors

  Name Description
Public method LinqDataSourceContextEventArgs() Initializes a new instance of the LinqDataSourceContextEventArgs class.
Public method LinqDataSourceContextEventArgs(DataSourceOperation) Initializes a new instance of the LinqDataSourceContextEventArgs class for the specified data operation.
Top
Properties

  Name Description
Public property ObjectInstance Gets or sets the data context object to create.
Public property Operation Gets the data operation that is being performed.
Top
Methods

  Name Description
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Top
Remarks

By default, the LinqDataSource control creates an instance of the type that is specified in the ContextTypeName property. The LinqDataSource control calls the default constructor of the data context object to create an instance of the object.

You can manually create the data context object by handling the ContextCreating event. You do this if you want to use a non-default constructor.

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. In that case, you set the ObjectInstance property to the object you created. The LinqDataSource control will use the object you have created for selecting the data. When you are updating, inserting, or deleting data, you must set the ObjectInstance property to an object that derives from the DataContext class.

Examples

The following example shows how to create the data context object by calling a non-default constructor in an event handler for the ContextCreating event. The code assigns the custom object to the ObjectInstance property.

Visual Basic

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


C#

protected void LinqDataSource_ContextCreating(object sender, LinqDataSourceContextEventArgs e)
{
    e.ObjectInstance = new ExampleDataContext(ConfigurationManager.ConnectionStrings["ExampleConnectionString"].ConnectionString);
}


Version Information

.NET Framework

Supported in: 4, 3.5
Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also

Reference

Other Resources