Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.SQLiteBackend/3.2/ModelResult.cs @ 2179

Last change on this file since 2179 was 2179, checked in by mkommend, 15 years ago

implemented final prototyp of LinqToSql mapping (ticket #712)

File size: 2.6 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Data.Linq;
4using System.Data.Linq.Mapping;
5using System.Text;
6
7namespace HeuristicLab.Modeling.SQLiteBackend {
8  [Table(Name = "ModelResult")]
9  public class ModelResult {
10    public ModelResult() {
11      this.model = default(EntityRef<Model>);
12      this.result = default(EntityRef<Result>);
13    }
14
15    public ModelResult(Model model, Result result, double value)
16      : this() {
17      this.Model = model;
18      this.Result = result;
19      this.value = value;
20    }
21
22    private double value;
23    [Column(Storage = "value", CanBeNull = false)]
24    public double Value {
25      get { return this.value; }
26      set { this.value = value; }
27    }
28
29    private int modelId;
30    [Column(Storage = "modelId", CanBeNull = false)]
31    public int ModelId {
32      get { return this.modelId; }
33      private set {
34        if (modelId != value) {
35          if (model.HasLoadedOrAssignedValue)
36            throw new ForeignKeyReferenceAlreadyHasValueException();
37        }
38        modelId = value;
39      }
40    }
41
42    private EntityRef<Model> model;
43    [Association(Storage = "model", ThisKey = "ModelId", OtherKey = "Id", IsForeignKey = true)]
44    public Model Model {
45      get { return this.model.Entity; }
46      set {
47        Model previousValue = model.Entity;
48        if (previousValue != value || (!model.HasLoadedOrAssignedValue)) {
49          if (previousValue != null) {
50            model.Entity = null;
51          }
52          model.Entity = value;
53          if (value != null) {
54            modelId = value.Id;
55          }
56        }
57      }
58    }
59
60    private int resultId;
61    [Column(Storage = "resultId", CanBeNull = false)]
62    public int ResultId {
63      get { return this.resultId; }
64      private set {
65        if (resultId != value) {
66          if (result.HasLoadedOrAssignedValue)
67            throw new ForeignKeyReferenceAlreadyHasValueException();
68        }
69        modelId = value;
70      }
71    }
72
73    private EntityRef<Result> result;
74    [Association(Storage = "result", ThisKey = "ResultId", OtherKey = "Id", IsForeignKey = true)]
75    public Result Result {
76      get { return this.result.Entity; }
77      set {
78        Result previousValue = result.Entity;
79        if (previousValue != value || (!model.HasLoadedOrAssignedValue)) {
80          if (previousValue != null) {
81            result.Entity = null;
82          }
83          result.Entity = value;
84          if (value != null) {
85            resultId = value.Id;
86          }
87        }
88      }
89    }
90
91  }
92}
Note: See TracBrowser for help on using the repository browser.