.NET Framework Class Library LinqDataSourceContextEventArgs Class

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

Syntax
Public Class LinqDataSourceContextEventArgs _
Inherits EventArgs
public class LinqDataSourceContextEventArgs : EventArgs
public ref class LinqDataSourceContextEventArgs : public EventArgs
type LinqDataSourceContextEventArgs =
class
inherit EventArgs
end
The LinqDataSourceContextEventArgs type exposes the following members.

Constructors

Methods

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.
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
protected void LinqDataSource_ContextCreating(object sender, LinqDataSourceContextEventArgs e)
{
e.ObjectInstance = new ExampleDataContext(ConfigurationManager.ConnectionStrings["ExampleConnectionString"].ConnectionString);
}

Version Information
.NET FrameworkSupported in: 4, 3.5

Platforms
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role not supported), 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
|
Bibliothèque de classes .NET Framework LinqDataSourceContextEventArgs, classe

Hiérarchie d'héritage
Espace de noms :
System.Web.UI.WebControls
Assembly :
System.Web.Extensions (dans System.Web.Extensions.dll)

Syntaxe
Public Class LinqDataSourceContextEventArgs _
Inherits EventArgs
public class LinqDataSourceContextEventArgs : EventArgs
public ref class LinqDataSourceContextEventArgs : public EventArgs
type LinqDataSourceContextEventArgs =
class
inherit EventArgs
end
Le type LinqDataSourceContextEventArgs expose les membres suivants.

Constructeurs

Méthodes

Notes
Par défaut, le contrôle LinqDataSource crée une instance du type spécifié dans la propriété ContextTypeName. Le contrôle LinqDataSource appelle le constructeur par défaut de l'objet de contexte de données pour créer une instance de l'objet. Vous pouvez créer manuellement l'objet de contexte de données en gérant l'événement ContextCreating. Vous procédez ainsi si vous souhaitez utiliser un constructeur autre que celui par défaut. Vous pouvez également gérer l'événement ContextCreating si vous souhaitez créer un objet de contexte de données différent de celui spécifié dans la propriété ContextTypeName. Dans ce cas, vous affectez comme valeur à la propriété ObjectInstance l'objet que vous avez créé. Le contrôle LinqDataSource utilisera l'objet que vous avez créé pour sélectionner les données. Lorsque vous mettez à jour, insérez ou supprimez des données, vous devez affecter comme valeur à la propriété ObjectInstance un objet qui dérive de la classe DataContext.

Exemples
L'exemple suivant indique comment créer l'objet de contexte de données en appelant un constructeur autre que celui par défaut dans un gestionnaire d'événements pour l'événement ContextCreating. Le code assigne l'objet personnalisé à la propriété ObjectInstance.
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
protected void LinqDataSource_ContextCreating(object sender, LinqDataSourceContextEventArgs e)
{
e.ObjectInstance = new ExampleDataContext(ConfigurationManager.ConnectionStrings["ExampleConnectionString"].ConnectionString);
}

Informations de version
.NET FrameworkPris en charge dans : 4, 3.5

Plateformes
Windows 7, Windows Vista SP1 ou ultérieur, Windows XP SP3, Windows Server 2008 (installation minimale non prise en charge), Windows Server 2008 R2 (installation minimale prise en charge avec SP1 ou version ultérieure), Windows Server 2003 SP2
Le .NET Framework ne prend pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.

Sécurité des threads
Tous les membres static ( Shared en Visual Basic) publics de ce type sont thread-safe. Il n'est pas garanti que les membres d'instance soient thread-safe.

Voir aussi
RéférenceAutres ressources
|