如果需要SubSonic直接执行SQL语句,应该如何处理呢?下面为您介绍的就是SubSonic直接执行SQL语句的方法,希望对您有所帮助。
SubSonic直接执行SQL语句可以使用以下方式:
- 01 public void Inline_Simple()
- 02 {
- 03 QueryCommand cmd = new InlineQuery().GetCommand("SELECT productID from products");
- 04 Assert.IsTrue(cmd.CommandSql ==
- 05 "SELECT productID from products");
- 06 }
- 07
- 08 public void Inline_WithCommands()
- 09 {
- 10 QueryCommand cmd = new InlineQuery()
- 11 .GetCommand(@"SELECT productID from products
- 12 WHERE productid=@productid", 1);
- 13
- 14 Assert.IsTrue(cmd.Parameters[0].ParameterName == "@productid");
- 15 Assert.IsTrue((int)cmd.Parameters[0].ParameterValue == 1);
- 16 }
- 17
- 18 public void Inline_AsCollection()
- 19 {
- 20 ProductCollection products =
- 21 new InlineQuery()
- 22 .ExecuteAsCollection
( - 23 @"SELECT productID from products
- 24 WHERE productid=@productid", 1);
- 25 }
注意:可能需要指定DataProvider
【编辑推荐】
巧用SQL语句删除重复记录
批量执行SQL语句的示例
教您使用SQL语句修改SQL主键
逐条更新数据的SQL语句写法
对存储过程代替SQL语句的讨论
上一篇:掌握DHCP超级作用域的添加方法
下一篇:受宠的背后:安全市场面临重新洗牌