コード例 #1
0
        public async Task TestAdd()
        {
            OrderClient client = OrderClientUtils.CreateOrderClient();

            context.OrderClients.Add(client);
            // 将结果写入到数据库
            int result = await context.SaveChangesAsync();

            Assert.IsTrue(result == 1);
            Console.WriteLine(client);

            // 读取数据库
            OrderClient clientFromDB = await context.OrderClients.FirstOrDefaultAsync(c => c.ClientID == client.ClientID);

            Assert.IsNotNull(clientFromDB);
            //检测两个OrderClient对象是相等的
            Assert.IsTrue(clientFromDB.Equals(client));
        }
コード例 #2
0
 public void TestAdd()
 {
     using (var context = new MyDBContext())
     {
         //创建一个新的数据实体
         OrderClient client = OrderClientHelper.CreateOrderClient();
         context.OrderClients.Add(client);
         int result = context.SaveChanges();
         Assert.IsTrue(result == 1);
         Console.WriteLine(client);
         //从数据库中重新装载数据
         OrderClient clientFromDB = context.OrderClients.FirstOrDefault(
             c => c.ClientID == client.ClientID
             );
         Assert.IsNotNull(clientFromDB);
         //检测两个OrderClient对象是相等的
         Assert.IsTrue(clientFromDB.Equals(client));
     }
 }