是否可以将NoTracking(MergeOption.NoTracking)与EntityDatSource控件一起使用?

时间:2011-06-04 06:26:18

标签: asp.net entity-framework

有人能告诉我是否可以将NoTracking(MergeOption.NoTracking)与EntityDatSource控件一起使用?

若然,怎么样?

1 个答案:

答案 0 :(得分:0)

实施ContextCreating事件的处理并为MergeOption设置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;
    }
}

在标记中使用:

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