有人能告诉我是否可以将NoTracking(MergeOption.NoTracking)与EntityDatSource控件一起使用?
若然,怎么样?
答案 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" />