假如需要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<ProductCollection>( 23 @"SELECT productID from products 24 WHERE productid=@productid", 1); 25 }
注意:可能需要指定DataProvider