Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/23/09 11:01:40 (15 years ago)
Author:
mkommend
Message:

implemented final prototyp of LinqToSql mapping (ticket #712)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.SQLiteBackend/3.2/Model.cs

    r2178 r2179  
    66using System.Text;
    77
    8 namespace HeuristicLab.Modeling.SQLiteBackend { 
    9   [Table(Name="Model")]
     8namespace HeuristicLab.Modeling.SQLiteBackend {
     9  [Table(Name = "Model")]
    1010  public class Model {
    1111    public Model() {
     
    1414    }
    1515
     16    public Model(Variable targetVariable, Algorithm algorithm, object data)
     17      : this() {
     18      this.TargetVariable = targetVariable;
     19      this.Algorithm = algorithm;
     20      this.data = data;
     21    }
     22
    1623    private int id;
    17     [Column(Storage = "id", DbType = "integer", IsPrimaryKey = true, IsDbGenerated = true, UpdateCheck = UpdateCheck.Never)]
     24    [Column(Storage = "id", IsPrimaryKey = true, IsDbGenerated = true)]
    1825    public int Id {
    1926      get { return this.id; }
     
    2229
    2330    private object data;
    24     [Column(Storage = "data", DbType = "text", CanBeNull = false)]
     31    [Column(Storage = "data", DbType = "varbinary(8000)", CanBeNull = false)]
    2532    public object Data {
    2633      get { return this.data; }
     
    2936
    3037    private int algorithmId;
    31     [Column(Storage="algorithmId", DbType="Int not null")]
     38    [Column(Storage = "algorithmId", CanBeNull = false)]
    3239    public int AlgorithmId {
    33       get { return this.algorithmId;}
    34       private set { 
    35         if(algorithmId != value) {
    36           if(algorithm.HasLoadedOrAssignedValue)
     40      get { return this.algorithmId; }
     41      private set {
     42        if (algorithmId != value) {
     43          if (algorithm.HasLoadedOrAssignedValue)
    3744            throw new ForeignKeyReferenceAlreadyHasValueException();
    38           algorithmId =value;
     45          algorithmId = value;
    3946        }
    4047      }
    4148    }
    4249
    43 
    4450    private EntityRef<Algorithm> algorithm;
    45     [Association(Storage="algorithm",ThisKey="AlgorithmId",OtherKey="Id",IsForeignKey=true)]
     51    [Association(Storage = "algorithm", ThisKey = "AlgorithmId", OtherKey = "Id", IsForeignKey = true)]
    4652    public Algorithm Algorithm {
    4753      get { return this.algorithm.Entity; }
     
    4955        Algorithm previousValue = algorithm.Entity;
    5056        if (previousValue != value || (!algorithm.HasLoadedOrAssignedValue)) {
    51           if (previousValue == null) {
     57          if (previousValue != null) {
    5258            algorithm.Entity = null;
    53             previousValue.Models.Remove(this);
    5459          }
    5560          algorithm.Entity = value;
    5661          if (value != null) {
    57             value.Models.Add(this);
    5862            algorithmId = value.Id;
    59           } else
    60             throw new NullReferenceException("Null not allowed as value for Model.Algorithm");
     63          }
    6164        }
    6265      }
     
    6467
    6568    private int targetVariableId;
    66     [Column(Storage = "targetVariableId", DbType = "Int not null")]
     69    [Column(Storage = "targetVariableId", CanBeNull = false)]
    6770    public int TargetVariableId {
    6871      get { return this.targetVariableId; }
     
    8386        Variable previousValue = targetVariable.Entity;
    8487        if (previousValue != value || (!targetVariable.HasLoadedOrAssignedValue)) {
    85           if (previousValue == null) {
     88          if (previousValue != null) {
    8689            targetVariable.Entity = null;
    87             previousValue.ModelsPredictingThisVariable.Remove(this);
    8890          }
    8991          targetVariable.Entity = value;
    9092          if (value != null) {
    91             value.ModelsPredictingThisVariable.Add(this);
    9293            targetVariableId = value.Id;
    93           } else
    94             throw new NullReferenceException("Null not allowed as value for Model.TargetVariable");
     94          }
    9595        }
    9696      }
    9797    }
    9898
    99     public IEnumerable<Variable> inputVariables {
     99    public IEnumerable<Variable> InputVariables {
    100100      get {
    101101        using (ModelingDataContext ctx = new ModelingDataContext()) {
     
    107107      }
    108108    }
     109
     110    public Dictionary<string, double> ResultValues {
     111      get {
     112        using (ModelingDataContext ctx = new ModelingDataContext()) {
     113          var x = (from modelResult in ctx.ModelResults
     114                   where modelResult.Model == this
     115                   select modelResult)
     116                  .ToDictionary(
     117                    modelResult => modelResult.Result.Name,
     118                    modelResult => modelResult.Value);
     119          return x;
     120        }
     121      }
     122    }
    109123  }
    110124}
Note: See TracChangeset for help on using the changeset viewer.