Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.SQLiteBackend/3.2/Variable.cs @ 2178

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

added first implementation of LinqToSql mapping (ticket #712)

File size: 1.8 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Data.Linq;
5using System.Data.Linq.Mapping;
6using System.Text;
7
8namespace HeuristicLab.Modeling.SQLiteBackend {
9  [Table(Name = "Variable")]
10  public class Variable {
11    public Variable() {
12      modelsPredictingThisVariable = new EntitySet<Model>(attach_Model, detach_Model);
13    }
14
15    private int id;
16    [Column(Storage = "id", DbType = "integer", IsPrimaryKey = true, IsDbGenerated = true, UpdateCheck = UpdateCheck.Never)]
17    public int Id {
18      get { return this.id; }
19      private set { this.id = value; }
20    }
21
22    private string name;
23    [Column(Storage = "name", DbType = "VarChar(50) NOT NULL", CanBeNull = false)]
24    public string Name {
25      get { return this.name; }
26      private set { this.name = value; }
27    }
28
29    private EntitySet<Model> modelsPredictingThisVariable;
30    [Association(Storage = "modelsPredictingThisVariable", ThisKey = "Id", OtherKey = "TargetVariableId")]
31    public EntitySet<Model> ModelsPredictingThisVariable {
32      get {
33        if (modelsPredictingThisVariable.HasLoadedOrAssignedValues)
34          return modelsPredictingThisVariable;
35        return null;
36      }
37      set {
38        modelsPredictingThisVariable.Assign(value);
39      }
40    }
41
42    private void attach_Model(Model model) {
43      model.TargetVariable = this;
44    }
45
46    private void detach_Model(Model model) {
47      model.TargetVariable = null;
48    }
49
50    public IEnumerable<Model> ModelsUsingThisVariable {
51      get {
52        using (ModelingDataContext ctx = new ModelingDataContext()) {
53          var x = from inputVariable in ctx.InputVariables
54                  where inputVariable.Variable == this
55                  select inputVariable.Model;
56          return x.AsEnumerable();
57        }
58      }
59    }
60  }
61}
Note: See TracBrowser for help on using the repository browser.