Changeset 2179 for branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.SQLiteBackend/3.2/Model.cs
- Timestamp:
- 07/23/09 11:01:40 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.SQLiteBackend/3.2/Model.cs
r2178 r2179 6 6 using System.Text; 7 7 8 namespace HeuristicLab.Modeling.SQLiteBackend { 9 [Table(Name ="Model")]8 namespace HeuristicLab.Modeling.SQLiteBackend { 9 [Table(Name = "Model")] 10 10 public class Model { 11 11 public Model() { … … 14 14 } 15 15 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 16 23 private int id; 17 [Column(Storage = "id", DbType = "integer", IsPrimaryKey = true, IsDbGenerated = true, UpdateCheck = UpdateCheck.Never)]24 [Column(Storage = "id", IsPrimaryKey = true, IsDbGenerated = true)] 18 25 public int Id { 19 26 get { return this.id; } … … 22 29 23 30 private object data; 24 [Column(Storage = "data", DbType = " text", CanBeNull = false)]31 [Column(Storage = "data", DbType = "varbinary(8000)", CanBeNull = false)] 25 32 public object Data { 26 33 get { return this.data; } … … 29 36 30 37 private int algorithmId; 31 [Column(Storage ="algorithmId", DbType="Int not null")]38 [Column(Storage = "algorithmId", CanBeNull = false)] 32 39 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) 37 44 throw new ForeignKeyReferenceAlreadyHasValueException(); 38 algorithmId = value;45 algorithmId = value; 39 46 } 40 47 } 41 48 } 42 49 43 44 50 private EntityRef<Algorithm> algorithm; 45 [Association(Storage ="algorithm",ThisKey="AlgorithmId",OtherKey="Id",IsForeignKey=true)]51 [Association(Storage = "algorithm", ThisKey = "AlgorithmId", OtherKey = "Id", IsForeignKey = true)] 46 52 public Algorithm Algorithm { 47 53 get { return this.algorithm.Entity; } … … 49 55 Algorithm previousValue = algorithm.Entity; 50 56 if (previousValue != value || (!algorithm.HasLoadedOrAssignedValue)) { 51 if (previousValue == null) {57 if (previousValue != null) { 52 58 algorithm.Entity = null; 53 previousValue.Models.Remove(this);54 59 } 55 60 algorithm.Entity = value; 56 61 if (value != null) { 57 value.Models.Add(this);58 62 algorithmId = value.Id; 59 } else 60 throw new NullReferenceException("Null not allowed as value for Model.Algorithm"); 63 } 61 64 } 62 65 } … … 64 67 65 68 private int targetVariableId; 66 [Column(Storage = "targetVariableId", DbType = "Int not null")]69 [Column(Storage = "targetVariableId", CanBeNull = false)] 67 70 public int TargetVariableId { 68 71 get { return this.targetVariableId; } … … 83 86 Variable previousValue = targetVariable.Entity; 84 87 if (previousValue != value || (!targetVariable.HasLoadedOrAssignedValue)) { 85 if (previousValue == null) {88 if (previousValue != null) { 86 89 targetVariable.Entity = null; 87 previousValue.ModelsPredictingThisVariable.Remove(this);88 90 } 89 91 targetVariable.Entity = value; 90 92 if (value != null) { 91 value.ModelsPredictingThisVariable.Add(this);92 93 targetVariableId = value.Id; 93 } else 94 throw new NullReferenceException("Null not allowed as value for Model.TargetVariable"); 94 } 95 95 } 96 96 } 97 97 } 98 98 99 public IEnumerable<Variable> inputVariables {99 public IEnumerable<Variable> InputVariables { 100 100 get { 101 101 using (ModelingDataContext ctx = new ModelingDataContext()) { … … 107 107 } 108 108 } 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 } 109 123 } 110 124 }
Note: See TracChangeset
for help on using the changeset viewer.