using System; using System.Collections.Generic; using System.Linq; using System.Data.Linq; using System.Data.Linq.Mapping; using System.Text; namespace HeuristicLab.Modeling.SQLiteBackend { [Table(Name = "Variable")] public class Variable { public Variable() { modelsPredictingThisVariable = new EntitySet(attach_Model, detach_Model); } private int id; [Column(Storage = "id", DbType = "integer", IsPrimaryKey = true, IsDbGenerated = true, UpdateCheck = UpdateCheck.Never)] public int Id { get { return this.id; } private set { this.id = value; } } private string name; [Column(Storage = "name", DbType = "VarChar(50) NOT NULL", CanBeNull = false)] public string Name { get { return this.name; } private set { this.name = value; } } private EntitySet modelsPredictingThisVariable; [Association(Storage = "modelsPredictingThisVariable", ThisKey = "Id", OtherKey = "TargetVariableId")] public EntitySet ModelsPredictingThisVariable { get { if (modelsPredictingThisVariable.HasLoadedOrAssignedValues) return modelsPredictingThisVariable; return null; } set { modelsPredictingThisVariable.Assign(value); } } private void attach_Model(Model model) { model.TargetVariable = this; } private void detach_Model(Model model) { model.TargetVariable = null; } public IEnumerable ModelsUsingThisVariable { get { using (ModelingDataContext ctx = new ModelingDataContext()) { var x = from inputVariable in ctx.InputVariables where inputVariable.Variable == this select inputVariable.Model; return x.AsEnumerable(); } } } } }