コード例 #1
0
        private static void InsertData()
        {
            var cars = ProcessCars("fuel.csv");
            var db   = new CarDatabase();

            db.Database.Log = Console.WriteLine;

            if (!db.Cars.Any())
            {
                foreach (var car in cars)
                {
                    db.Cars.Add(car);
                }
                db.SaveChanges();
            }
        }
コード例 #2
0
        private static void QueryData()
        {
            var db = new CarDatabase();

            db.Database.Log = Console.WriteLine;

            // Get all cars and order the cars by highway fuel efficiency
            var query = db.Cars.OrderByDescending(c => c.Highway)
                        .ThenBy(c => c.Name)
                        .Take(5);

            foreach (var car in query)
            {
                Console.WriteLine($"{car.Name}: {car.Highway}");
            }
        }