ibatis.net:第四天,Update 和 Delete
xml
1 <update id="UpdateOrder" parameterClass="Order"> 2 UPDATE [Orders] SET Customer = #Customer# WHERE Id = #Id# 3 </update> 4 <delete id="DeleteOrder" parameterClass="Order"> 5 DELETE FROM [Orders] WHERE Id = #Id# 6 </delete>
代码
1 public static void UpdateOrder() 2 { 3 var mapper = Mapper.Instance(); 4 5 var order = new Order 6 { 7 Customer = "段光伟" 8 }; 9 mapper.Insert("InsertOrder", order); 10 Console.WriteLine(mapper.Update("UpdateOrder", order)); 11 Console.WriteLine(mapper.Delete("DeleteOrder", order)); 12 }
备注
Update 和 Delete 都返回受影响的行数。有一个需要重点考虑的是:乐观并发处理,框架好像并没有给予支持,估计需要我们自己处理(后面单独找一篇文章看看)。