问题描述
|
谁能告诉我是否可以在EntityDatSource控件中使用NoTracking(MergeOption.NoTracking)?
如果是这样,怎么办?
解决方法
实施
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\" />