Beispiel #1
0
        static void Main(string[] args)
        {
            var service = new OrderService();

            for (int i = 1; i <= 10; i++)//填充 10 个随机订单
            {
                service.AddOrder(RandomOrder.RandOrder());
            }
            service.Export("service.xml");                //导出到 xml
            service = OrderService.Import("service.xml"); //从 xml 导入
            //用 LINQ 语法查询
            var result = from order in service
                         where order.PriceSum > 10
                         orderby order.Id
                         select order;

            foreach (var order in result)
            {
                Console.WriteLine(order);
                Console.WriteLine("---------------------------------");
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var service = new SqliteOrderService(
                "C:/Users/zhb/Documents/sqlitedb/order.db");

            service.DeleteAllData();      //删除之前的数据
            for (int i = 1; i <= 10; i++) //填充 10 个随机订单
            {
                service.AddOrder(RandomOrder.RandOrder());
            }

            //用 LINQ 语法查询
            Console.WriteLine("查询总价超过 200 元的订单,按订单 ID 排序。");
            var result = from order in service
                         where order.PriceSum > 200
                         orderby order.OrderId
                         select order;

            foreach (var order in result)
            {
                Console.WriteLine(order);
                Console.WriteLine("---------------------------------");
            }

            Console.WriteLine("查询含单价超过 50 元商品的订单,按订单 ID 排序。");
            result = from order in service
                     where order.OrderDetails.Find(detail => detail.Commodity.Price > 50) != null
                     orderby order.OrderId
                     select order;

            foreach (var order in result)
            {
                Console.WriteLine(order);
                Console.WriteLine("---------------------------------");
            }
        }