c# - Entity Framework taking minutes to save 7500 entries -


i've got pair of entity classes called signal , data:

public class data {     public data()     {     }      public int dataid { get; set; }      public double elapsedtime { get; set; }     public double x { get; set; }     public double y { get; set; }     public double value { get; set; } }  public class signal {     public signal()     {         data = new list<data>();     }      public int signalid { get; set; }      public string name { get; set; }     public string units { get; set; }     public virtual list<data> data { get; set; } } 

during normal operation, initialize database context , create necessary signals (12 of them), dispose context.

later, data being acquired hardware , initialize context again, create data objects, , add them appropriate signal. acquisition starts , stops on course of whole thing end 625 data points per signal (total of 7500 data points) in several short bursts on 10 seconds in total. have separate thread responsible saving data database, , hope won't lag far behind acquisition thread. however, after acquisition finished, takes 6-7 minutes data finish being saved.

below code being called every 100 data objects. dequeue dictionary acquisition thread. dictionary matches signals next 100 data objects need added them. grab matching signals database , add appropriate data.

// dequeue next set of data save  dictionary<signal, list<data>> datatosave = null; while (measurementdatatosavequeue.trydequeue(out datatosave) == false && measurementdatatosavequeue.count > 0)     if (sequenceaborted || sequenceinprogress == false) break;  if (datatosave != null && datatosave.count > 0) {     foreach (var pair in datatosave)     {         signal signal = dbcontext.signals.firstordefault(s => s.signalid == pair.key.signalid);         signal.data.addrange(pair.value);     } } 

the code above takes 10-20ms per call, , keeps acquisition fine. however, once 7500 data objects have been added appropriate signal, call dbcontext.savechanges() , takes several minutes. i've tried saving every time code runs instead, , each individual save faster, total time still 6-7 minutes. there way speed up? doesn't seem should take long update 7500 records.

thanks help.

using entityframework.bulkinsert should speed performance significantly.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -