Esempio n. 1
0
 public IEnumerable<Toilet> Get()
 {
     using (GotToGoContext context = new GotToGoContext())
     {
         return context.Toilets.ToList();
     }
 }
Esempio n. 2
0
        static void Main(string[] args)
        {
            List<Toilet> toilets = LoadFromXml();
            Console.WriteLine(string.Format(
                "About to load {0} toilets from XML to database. Press enter to proceed.", toilets.Count));

            Console.ReadLine();
            Console.WriteLine("Connecting...");

            using (SqlConnection connection = new SqlConnection(GotToGoConfig.Current.ConnectionString))
            using (SqlCommand command = new SqlCommand("TRUNCATE TABLE Toilets", connection))
            {
                connection.Open();
                command.ExecuteNonQuery();
            }

            Console.WriteLine("Loading toilet data...");

            GotToGoContext context = new GotToGoContext();

            try
            {
                for (int i = 0; i < toilets.Count; i++)
                {
                    context.Toilets.Add(toilets[i]);

                    if (i % 200 == 199 || i == toilets.Count - 1)
                    {
                        context.SaveChanges();
                        Console.WriteLine(string.Format("  {0:0.0}%", (i + 1) * 100.0 / toilets.Count));

                        context.Dispose();
                        context = new GotToGoContext();
                    }
                }
            }
            finally
            {
                context.Dispose();
            }

            Console.WriteLine("Done!");
            Console.ReadLine();
        }