SubSonic直接执行SQL语句
SubSonic直接执行SQL语句可以使用以下方式:
public void Inline_Simple() { QueryCommand cmd = new InlineQuery().GetCommand("SELECT productID from products"); Assert.IsTrue(cmd.CommandSql == "SELECT productID from products"); } public void Inline_WithCommands() { QueryCommand cmd = new InlineQuery() .GetCommand(@"SELECT productID from products WHERE productid=@productid", 1); Assert.IsTrue(cmd.Parameters[0].ParameterName == "@productid"); Assert.IsTrue((int)cmd.Parameters[0].ParameterValue == 1); } public void Inline_AsCollection() { ProductCollection products = new InlineQuery() .ExecuteAsCollection<ProductCollection>( @"SELECT productID from products WHERE productid=@productid", 1); }
注意:可能需要指定DataProvider,在应用中可能需要session的支持。