public void QueryDB() { using (YijingEntities ye = new YijingEntities()) { Type t = ye.Types.Find(3); LabelSery ls2 = ye.LabelSeries.Where(ls1 => ls1.Name == "Vivash" && ls1.TypeId == (int)Sequences.ValueType.Hexagram).First(); // .OrderBy(ls1 => ls1.Name) IEnumerable <LabelSery> iels = from ls3 in ye.LabelSeries where ls3.TypeId == (int)Sequences.ValueType.Line orderby ls3.Name select ls3; List <LabelSery> lls = iels.ToList(); LabelSery ls4 = ye.LabelSeries.Include(ls => ls.Type).Include(ls => ls.Labels).Single(ls5 => ls5.Name == "Vivash"); Label l1 = ls2.Labels.Single(l => l.LabelData == "Return"); t = l1.Type; int x = 0; } }
public void InitialseDB() { using (YijingEntities ye = new YijingEntities()) { //List<Type> lt1 = ye.Types.ToList(); // Force access ye.Database.EnsureDeleted(); //ye.Database.EnsureCreated(); ye.Database.Migrate(); //List<Type> lt2 = ye.Types.ToList(); // Force access } using (YijingEntities ye = new YijingEntities()) { IQueryable <Sequence> iqs = ye.Sequences; IQueryable <Ratio> iqr = ye.Ratios; IQueryable <Label> iql = ye.Labels; IQueryable <Text> iqtx = ye.Texts; IQueryable <SequenceSery> iqss = ye.SequenceSeries; IQueryable <RatioSery> iqrs = ye.RatioSeries; IQueryable <LabelSery> iqls = ye.LabelSeries; IQueryable <TextSery> iqts = ye.TextSeries; IQueryable <TextType> iqtt = ye.TextTypes; IQueryable <Value> iqv = ye.Values; IQueryable <Type> iqt = ye.Types; ye.Sequences.RemoveRange(iqs); ye.Ratios.RemoveRange(iqr); ye.Labels.RemoveRange(iql); ye.Texts.RemoveRange(iqtx); ye.SequenceSeries.RemoveRange(iqss); ye.RatioSeries.RemoveRange(iqrs); ye.LabelSeries.RemoveRange(iqls); ye.TextSeries.RemoveRange(iqts); ye.TextTypes.RemoveRange(iqtt); ye.Values.RemoveRange(iqv); ye.Types.RemoveRange(iqt); SaveChanges(ye); } List <Type> lt = new List <Type>(); lt.Add(new Type() { Id = (int)Sequences.ValueType.Bit, Size = 2, Name = "Bit" }); lt.Add(new Type() { Id = (int)Sequences.ValueType.Line, Size = 4, Name = "Line" }); lt.Add(new Type() { Id = (int)Sequences.ValueType.Duogram, Size = 4, Name = "Duogram" }); lt.Add(new Type() { Id = (int)Sequences.ValueType.Trigram, Size = 8, Name = "Trigram" }); lt.Add(new Type() { Id = (int)Sequences.ValueType.Hexagram, Size = 64, Name = "Hexagram" }); List <Value> lv = new List <Value>(); foreach (Type t in lt) { for (int i = 0; i < t.Size; ++i) { lv.Add(new Value() { TypeId = t.Id, ValueId = i, }); } } List <TextType> ltt = new List <TextType>(); foreach (String s in Sequences.TextType) { ltt.Add(new TextType() { Name = s }); } using (YijingEntities ye = new YijingEntities()) { ye.Types.AddRange(lt); ye.Values.AddRange(lv); ye.TextTypes.AddRange(ltt); SaveChanges(ye); } using (YijingEntities ye = new YijingEntities()) { List <Sequence> ls = new List <Sequence>(); List <Ratio> lr = new List <Ratio>(); List <Label> ll = new List <Label>(); List <Text> ltx = new List <Text>(); for (int dt = 0; dt < 3; ++dt) { for (int ds = 1; ds < 14; ++ds) { int size = 0; String sequence = Sequences.strDiagramSettings[SettingIndex(dt, 0), ds]; if (sequence.Length > 0) { SequenceSery ss1 = new SequenceSery() { TypeId = DiagramType(dt), Name = sequence }; ye.SequenceSeries.Add(ss1); SaveChanges(ye); size = ye.Types.Find(ss1.TypeId).Size; for (int dv = 0; dv < size; ++dv) { ls.Add(new Sequence() { TypeId = DiagramType(dt), ValueId = dv, SequenceSeryId = ss1.Id, SequenceData = SequenceArray(dt)[ds - 1, dv] }); } } String ratio = Sequences.strDiagramSettings[SettingIndex(dt, 1), ds]; if (ratio.Length > 0) { RatioSery rs1 = new RatioSery() { TypeId = DiagramType(dt), Name = ratio }; ye.RatioSeries.Add(rs1); SaveChanges(ye); size = ye.Types.Find(rs1.TypeId).Size; for (int dv = 0; dv < size; ++dv) { lr.Add(new Ratio() { TypeId = DiagramType(dt), ValueId = dv, RatioSeryId = rs1.Id, RatioData = RatioArray(dt)[ds - 1, dv] }); } } String label = Sequences.strDiagramSettings[SettingIndex(dt, 2), ds]; if (label.Length > 0) { LabelSery ls1 = new LabelSery() { TypeId = DiagramType(dt), Name = label }; ye.LabelSeries.Add(ls1); SaveChanges(ye); size = ye.Types.Find(ls1.TypeId).Size; for (int dv = 0; dv < size; ++dv) { ll.Add(new Label() { TypeId = DiagramType(dt), ValueId = dv, LabelSeryId = ls1.Id, LabelData = LabelArray(dt)[ds - 1, dv] }); } } String text = Sequences.strDiagramSettings[SettingIndex(dt, 3), ds]; if (text.Length > 0) { TextSery ts1 = new TextSery() { TypeId = DiagramType(dt), Name = text }; ye.TextSeries.Add(ts1); SaveChanges(ye); size = ye.Types.Find(ts1.TypeId).Size; int tti = ye.TextTypes.Single(tt => tt.Name == "Text").Id; for (int dv = 0; dv < size; ++dv) { if (text.Length > 0) { ltx.Add(new Text() { TypeId = DiagramType(dt), ValueId = dv, TextSeryId = ts1.Id, TextTypeId = tti, TextData = Text(dt, text, "Text", dv) }); } } } } } ye.Sequences.AddRange(ls); ye.Ratios.AddRange(lr); ye.Labels.AddRange(ll); ye.Texts.AddRange(ltx); SaveChanges(ye); } }