EntityDataSource.ContextCreating Evento

Definição

Ocorre quando o EntityDataSource cria o ObjectContext que é usado para trabalhar com objetos de dados de entidade.Occurs when the EntityDataSource creates the ObjectContext that is used to work with entity data objects.

public:
 event EventHandler<System::Web::UI::WebControls::EntityDataSourceContextCreatingEventArgs ^> ^ ContextCreating;
public event EventHandler<System.Web.UI.WebControls.EntityDataSourceContextCreatingEventArgs> ContextCreating;
member this.ContextCreating : EventHandler<System.Web.UI.WebControls.EntityDataSourceContextCreatingEventArgs> 
Public Custom Event ContextCreating As EventHandler(Of EntityDataSourceContextCreatingEventArgs) 

Tipo de evento

EventHandler<EntityDataSourceContextCreatingEventArgs>

Exemplos

O exemplo a seguir mostra como criar uma ObjectContext variável do Page objeto e atribuí-la à Context Propriedade do EntityDataSourceContextCreatingEventArgs objeto.The following example shows how to create an ObjectContext variable of the Page object and assign it to the Context property of the EntityDataSourceContextCreatingEventArgs object.

public partial class _Default : System.Web.UI.Page
    {
        AdventureWorksModel.AdventureWorksEntities objCtx =
            new AdventureWorksModel.AdventureWorksEntities();

        protected void EntityDataSource2_ContextCreating(object sender,
            EntityDataSourceContextCreatingEventArgs e)
        {
            e.Context = objCtx;
        }
    }

Comentários

Manipule o ContextCreating evento para fornecer seu próprio ObjectContext , em vez de ter um novo ObjectContext criado.Handle the ContextCreating event to supply your own ObjectContext instead of having a new ObjectContext created. Se o ContextCreating evento não for tratado ou o manipulador não fornecer um ObjectContext , o EntityDataSource criará um de acordo com sua configuração.If the ContextCreating event is not handled or the handler does not provide an ObjectContext, the EntityDataSource creates one according to its configuration. Quando um ObjectContext é fornecido ao ContextCreating evento, a mesma instância é atribuída à Context Propriedade do objeto de evento de eventos sucessivos.When an ObjectContext is provided to the ContextCreating event, the same instance is assigned to the Context property of the event object of successive events. Para obter mais informações, consulte Gerenciamento de Life-Cycle de contexto de objeto (EntityDataSource).For more information, see Object Context Life-Cycle Management (EntityDataSource). Para obter mais informações sobre o contexto do objeto, consulte resolução de identidade, gerenciamento de estado e controle de alterações.For more information about the object context, see Identity Resolution, State Management, and Change Tracking.

Aplica-se a