LinqDataSourceContextEventArgs Classe
Definição
Fornece dados para o evento de 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
- Herança
Exemplos
O exemplo a seguir mostra como criar o objeto de contexto de dados chamando um construtor sem parâmetros em um manipulador de eventos para o ContextCreating evento.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. O código atribui o objeto personalizado à ObjectInstance propriedade.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
Comentários
Por padrão, o LinqDataSource controle cria uma instância do tipo que é especificado na ContextTypeName propriedade.By default, the LinqDataSource control creates an instance of the type that is specified in the ContextTypeName property. O LinqDataSource controle chama o construtor sem parâmetros do objeto de contexto de dados para criar uma instância do objeto.The LinqDataSource control calls the parameterless constructor of the data context object to create an instance of the object.
Você pode criar manualmente o objeto de contexto de dados manipulando o ContextCreating evento.You can manually create the data context object by handling the ContextCreating event. Você deve fazer isso se quiser usar um construtor sem parâmetros.You do this if you want to use a non-parameterless constructor.
Você também pode manipular o ContextCreating evento se quiser criar um objeto de contexto de dados diferente daquele especificado na ContextTypeName propriedade.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. Nesse caso, você define a ObjectInstance propriedade para o objeto que você criou.In that case, you set the ObjectInstance property to the object you created. O LinqDataSource controle usará o objeto que você criou para selecionar os dados.The LinqDataSource control will use the object you have created for selecting the data. Quando você estiver atualizando, inserindo ou excluindo dados, deverá definir a ObjectInstance propriedade para um objeto derivado da DataContext classe.When you are updating, inserting, or deleting data, you must set the ObjectInstance property to an object that derives from the DataContext class.
Construtores
| LinqDataSourceContextEventArgs() |
Inicializa uma nova instância da classe LinqDataSourceContextEventArgs.Initializes a new instance of the LinqDataSourceContextEventArgs class. |
| LinqDataSourceContextEventArgs(DataSourceOperation) |
Inicializa uma nova instância da classe LinqDataSourceContextEventArgs para a operação de dados especificada.Initializes a new instance of the LinqDataSourceContextEventArgs class for the specified data operation. |
Propriedades
| ObjectInstance |
Obtém ou define o objeto de contexto de dados a ser criado.Gets or sets the data context object to create. |
| Operation |
Obtém a operação de dados que está sendo executada.Gets the data operation that is being performed. |
Métodos
| Equals(Object) |
Determina se o objeto especificado é igual ao objeto atual.Determines whether the specified object is equal to the current object. (Herdado de Object) |
| GetHashCode() |
Serve como a função de hash padrão.Serves as the default hash function. (Herdado de Object) |
| GetType() |
Obtém o Type da instância atual.Gets the Type of the current instance. (Herdado de Object) |
| MemberwiseClone() |
Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object. (Herdado de Object) |
| ToString() |
Retorna uma cadeia de caracteres que representa o objeto atual.Returns a string that represents the current object. (Herdado de Object) |