EntityDataSource.ContextCreating イベント

定義

エンティティ データ オブジェクトの操作で使用される EntityDataSourceObjectContext が作成すると発生します。

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) 

イベントの種類

次の例は、 オブジェクトの変数を ObjectContext 作成し、 Page それを オブジェクトの プロパティに Context 割り当てる方法を EntityDataSourceContextCreatingEventArgs 示しています。

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;
        }
    }

注釈

イベントをContextCreating処理して、新しくObjectContext作成するのではなく、独自ObjectContextのものを指定します。 イベントが ContextCreating 処理されない場合、またはハンドラーが を ObjectContext提供しない場合、 EntityDataSource は、その構成に従ってイベントを作成します。 ObjectContextがイベントにContextCreating提供されると、連続するイベントのイベント オブジェクトの プロパティにContext同じインスタンスが割り当てられます。 詳細については、「 オブジェクト コンテキスト Life-Cycle管理 (EntityDataSource)」を参照してください。 オブジェクト コンテキストの詳細については、「ID 解決、状態管理、およびChange Tracking」を参照してください。

適用対象