Is it 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" />
精彩评论