开发者

Is it possible to use NoTracking (MergeOption.NoTracking) with the EntityDatSource Control?

开发者 https://www.devze.com 2023-03-11 12:16 出处:网络
Can anyone t开发者_JAVA技巧ell me if it is possible to use NoTracking (MergeOption.NoTracking) with the EntityDatSource Control?

Can anyone t开发者_JAVA技巧ell me if it is possible to use NoTracking (MergeOption.NoTracking) with the EntityDatSource Control?

If so, how?


Implement handling for ContextCreating event and set MergeOption for ObjectSet<T>:

public partial class YourPage : System.Web.UI.Page
{
    ...

    protected void EntityDataSource_ContextCreating(object sender, 
        EntityDataSourceContextCreatingEventArgs e)
    {
        e.Context = new YourContext();  // EntityDataSource handles disposing
        e.Context.YourObjectSet.MergeOption = MergeOption.NoTracking;
    }
}

And in the markup use:

<asp:EntityDataSource ... OnContextCreating="EntityDataSource_ContextCreating" />
0

精彩评论

暂无评论...
验证码 换一张
取 消