SubSonic直接执行SQL语句的方法


  本文标签:SQL语句

  如果需要SubSonic直接执行SQL语句,应该如何处理呢?下面为您介绍的就是SubSonic直接执行SQL语句的方法,希望对您有所帮助  。

  SubSonic直接执行SQL语句可以使用以下方式:

  1. 01 public void Inline_Simple()    
  2.  
  3. 02 {    
  4.  
  5. 03     QueryCommand cmd = new InlineQuery().GetCommand("SELECT productID from products");    
  6.  
  7. 04     Assert.IsTrue(cmd.CommandSql ==     
  8.  
  9. 05             "SELECT productID from products");    
  10.  
  11. 06 }    
  12.  
  13. 07     
  14.  
  15. 08 public void Inline_WithCommands()    
  16.  
  17. 09 {    
  18.  
  19. 10     QueryCommand cmd = new InlineQuery()    
  20.  
  21. 11            .GetCommand(@"SELECT productID from products     
  22.  
  23. 12                WHERE productid=@productid", 1);    
  24.  
  25. 13     
  26.  
  27. 14     Assert.IsTrue(cmd.Parameters[0].ParameterName == "@productid");    
  28.  
  29. 15     Assert.IsTrue((int)cmd.Parameters[0].ParameterValue == 1);    
  30.  
  31. 16 }    
  32.  
  33. 17     
  34.  
  35. 18 public void Inline_AsCollection()    
  36.  
  37. 19 {    
  38.  
  39. 20     ProductCollection products =    
  40.  
  41. 21         new InlineQuery()    
  42.  
  43. 22             .ExecuteAsCollection<ProductCollection>(    
  44.  
  45. 23                       @"SELECT productID from products     
  46.  
  47. 24                        WHERE productid=@productid", 1);    
  48.  
  49. 25 }   
  50.  

  注意:可能需要指定DataProvider