Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2452 for trunk/sources


Ignore:
Timestamp:
10/27/09 14:31:03 (15 years ago)
Author:
mkommend
Message:

added context usings to correct bug while persisting models (ticket #792)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/DatabaseService.cs

    r2451 r2452  
    160160
    161161    public void PersistModel(IModel model) {
    162       Model m = (Model)model;
    163       //check if model has to be updated or inserted
    164       if (ctx.Models.Any(x => x.Id == model.Id)) {
    165         Model orginal = ctx.Models.GetOriginalEntityState(m);
    166         if (orginal == null)
    167           ctx.Models.Attach(m);
    168         ctx.Refresh(RefreshMode.KeepCurrentValues, m);
    169       } else
    170         ctx.Models.InsertOnSubmit(m);
    171       ctx.SubmitChanges();
     162      using (ModelingDataContext ctx = new ModelingDataContext(this.ConnectionString)) {
     163        Model m = (Model)model;
     164        //check if model has to be updated or inserted
     165        if (ctx.Models.Any(x => x.Id == model.Id)) {
     166          Model orginal = ctx.Models.GetOriginalEntityState(m);
     167          if (orginal == null)
     168            ctx.Models.Attach(m);
     169          ctx.Refresh(RefreshMode.KeepCurrentValues, m);
     170        } else
     171          ctx.Models.InsertOnSubmit(m);
     172        ctx.SubmitChanges();
     173      }
    172174    }
    173175
     
    225227
    226228    public void PersistPredictor(IModel model, IPredictor predictor) {
    227       Model m = (Model)model;
    228       ctx.ModelData.DeleteAllOnSubmit(ctx.ModelData.Where(x => x.Model == m));
    229       ctx.ModelResults.DeleteAllOnSubmit(ctx.ModelResults.Where(x => x.Model == m));
    230       ctx.InputVariableResults.DeleteAllOnSubmit(ctx.InputVariableResults.Where(x => x.Model == m));
    231       ctx.InputVariables.DeleteAllOnSubmit(ctx.InputVariables.Where(x => x.Model == m));
    232 
    233       ctx.ModelData.InsertOnSubmit(new ModelData(m, PersistenceManager.SaveToGZip(predictor)));
    234       foreach (string variableName in predictor.GetInputVariables())
    235         ctx.InputVariables.InsertOnSubmit(new InputVariable(m, (Variable)GetVariable(variableName)));
    236 
    237       ctx.SubmitChanges();
     229      using (ModelingDataContext ctx = new ModelingDataContext(this.ConnectionString)) {
     230        Model m = (Model)model;
     231        ctx.ModelData.DeleteAllOnSubmit(ctx.ModelData.Where(x => x.Model == m));
     232        ctx.ModelResults.DeleteAllOnSubmit(ctx.ModelResults.Where(x => x.Model == m));
     233        ctx.InputVariableResults.DeleteAllOnSubmit(ctx.InputVariableResults.Where(x => x.Model == m));
     234        ctx.InputVariables.DeleteAllOnSubmit(ctx.InputVariables.Where(x => x.Model == m));
     235
     236        ctx.ModelData.InsertOnSubmit(new ModelData(m, PersistenceManager.SaveToGZip(predictor)));
     237        foreach (string variableName in predictor.GetInputVariables())
     238          ctx.InputVariables.InsertOnSubmit(new InputVariable(m, (Variable)GetVariable(variableName)));
     239
     240        ctx.SubmitChanges();
     241      }
    238242    }
    239243
Note: See TracChangeset for help on using the changeset viewer.