i trying use addrange method create bulk insert db.
this :
public virtual ienumerable<e> insertrange(ienumerable<e> entities) { context.set<e>().addrange(entities); if (isautosave) context.savechanges(); }
when call savechanges() exception saying:
conflicting changes detected. may happen when trying insert multiple entities same key.
i think problem might in model. id column, pk , identity of type int, cause new entities id=0. can solve that?
thanks, matan
maybe can try disable ef tracking - whatever need, save changes , enable back. increase performance of insert operation.
so, before calling method insert , save changes add this:
context.configuration.autodetectchangesenabled = false;
and when done enable back:
context.configuration.autodetectchangesenabled = true;
i hope you.
Comments
Post a Comment