Beispiel #1
0
        static void Main(string[] args)
        {
            //using (var db = new MigrationTestContext())
            //{
            //  for (var i = 0; i < 100; i++)
            //  {
            //    var newThing = db.MyThings.Add(new MyThing {FirstName = Guid.NewGuid().ToString()});
            //    Console.WriteLine("added newThing - " + newThing.FirstName);
            //  }
            //  db.SaveChanges();
            //}

            //Console.ReadLine();

            ReadWeightsFile();
            //Console.ReadLine();

            using (var db = new MigrationTestContext())
            {
                var values = db.WhiskeyTangoFoxtrots
                                             .Select(wtf => wtf)
                                             .OrderBy(wtf => wtf.Date)
                                             .ToList();
                foreach (var w in values)
                {
                    Console.WriteLine(w.Date.ToShortDateString() + " - " + w.Weight + " - " + w.Note + " - " + w.Id);
                }
            }

            Console.ReadLine();
        }
Beispiel #2
0
        private static void ReadWeightsFile()
        {
            var path = @"C:\Users\c-wallas\Desktop\r-and-d\migration_rnd\migration_rnd\measurements-weight-combined.csv";

            using (var db = new MigrationTestContext())
            {
                using (var reader = File.OpenText(path))
                {
                    var skipFirstLine = reader.ReadLine();
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        var fields = line.Split(',');
                        var date = DateTime.Parse(string.Format("{0} {1}", fields[0], fields[1]));
                        var value = decimal.Parse(fields[2]);
                        var note = fields[3];

                        //Console.WriteLine(date.ToShortDateString() + "," + value + "," + note);

                        db.WhiskeyTangoFoxtrots.AddOrUpdate(
                            wtf => wtf.Date,
                            new WhiskeyTangoFoxtrot { Id = Guid.NewGuid(), Date = date, Weight = value, Note = note }
                        );
                    }
                }
                db.SaveChanges();
            }
        }