static void PrintOrderForCustomer(AutoLot carsDB)
        {
            int custID = 0;

            Console.Write("Enter customer ID: ");
            custID = int.Parse(Console.ReadLine());

            var customerOrders =
                from cust in carsDB.Customers
                from o in cust.Orders
                where cust.CustID == custID
                select new { cust, o };

            Console.WriteLine("***** Order Info for Customer ID: {0}. *****", custID);
            foreach (var q in customerOrders)
            {
                Console.WriteLine("{0} {1} is order ID # {2}.",
                                  q.cust.FirstName.Trim(),
                                  q.cust.LastName.Trim(),
                                  q.o.OrderID);
                Console.WriteLine("{0} bought Car ID # {1}.",
                                  q.cust.FirstName.Trim(), q.o.CarID);
            }
            Console.WriteLine("\ncustomerOrders as a string: {0}", customerOrders);
        }
        static void Main(string[] args)
        {
            Console.WriteLine("***** More Fun with LINQ to SQL *****\n");
            AutoLot carsDB = new AutoLot(cnStr);

            InvokeStoredProc(carsDB);
            Console.WriteLine();
            PrintOrderForCustomer(carsDB);
            Console.ReadLine();
        }
        private static void InvokeStoredProc(AutoLot carsDB)
        {
            int    carID   = 0;
            string petName = "";

            Console.Write("Enter ID: ");
            carID = int.Parse(Console.ReadLine());

            // Invoke stored proc and print out the petname.
            carsDB.GetPetName(carID, ref petName);
            Console.WriteLine("Car ID {0} has the petname: {1}",
                              carID, petName);
        }
示例#4
0
 public LinqGen()
 {
     SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder
      {
     DataSource = @"(local)\SQLEXPRESS",
     InitialCatalog = "AutoLot",
     IntegratedSecurity = true
      };
      autoLot = new AutoLot( builder.ConnectionString );
      dataContext = new AutoLotObjectsDataContext( builder.ConnectionString );
      //InvokeStoredProcedure();
      //PrintOrder();
      //InsertNewCar();
      //UpdateCar();
      DeleteCar();
 }