示例#1
0
    static void Main(string[] args)
    {
        SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
        builder.DataSource = "localhost";
        builder.UserID = "sa";
        builder.Password = "******";
        builder.InitialCatalog = "TourAgency";

        try
        {
            DataContext db = new DataContext(builder.ConnectionString);
            db.ObjectTrackingEnabled = true;
            Table<Countries.Country> countries = db.GetTable<Countries.Country>();
            Table<Cities.City> cities = db.GetTable<Cities.City>();
            Table<Hotels.Hotel> hotels = db.GetTable<Hotels.Hotel>();
            Table<Tours.Tour> tours = db.GetTable<Tours.Tour>();
            Table<Clients.Client> clients = db.GetTable<Clients.Client>();
            Table<ClientsTours.ClientTour> clienttour = db.GetTable<ClientsTours.ClientTour>();

            XML.CreateXmlCountry(countries);
            XML.ReadXmlCountry();
            XML.ChangeXmlCountry();
            XML.AddXmlCountry();

            // пятизвездочные отели
            Sql.NStarsHotels(hotels, 5);
            // города России
            Sql.CitiesFromCountry(countries, cities, "Russia");

            Sql.AddClient(ref db, "AAA", "aaa", "88888888888", "*****@*****.**");
            Sql.ChangeClientEmail(ref db, "*****@*****.**");
            Sql.DeleteClient(ref db);

            UserDataContext udb = new UserDataContext(builder.ConnectionString);
            int count = 0;
            udb.FindClients(2, ref count);
            Console.WriteLine("Клиенты сделавшие {0} заказа: {1}", 2, count);

            SqlLinq.sql1(countries);
            SqlLinq.sql2("Argentina", countries, cities);
            SqlLinq.sql3(countries, cities);
            SqlLinq.sql4(hotels);
            SqlLinq.sql5(tours, clienttour);
        }
        catch (SqlException e)
        {
            Console.WriteLine(e.ToString());
        }
    }