本文整理汇总了C#中Database.SqlQuery方法的典型用法代码示例。如果您正苦于以下问题:C# Database.SqlQuery方法的具体用法?C# Database.SqlQuery怎么用?C# Database.SqlQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Database
的用法示例。
在下文中一共展示了Database.SqlQuery方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ThenMatchedResultsAreReturned
public void ThenMatchedResultsAreReturned()
{
// Biuld
string nameOrConnectionString = "name=DefaultConnection";
IDatabase db = new Database(nameOrConnectionString, DbContextConnectionFactory.Get());
var criteria = new { Id = 1 };
// Operator
List<Category> categories = db.SqlQuery<Category>("dbo.GetCategory", criteria).ToList();
// Check
foreach (Category cat in categories)
{
Assert.AreEqual(criteria.Id, cat.Id);
}
}
示例2: With_valid_arguments_dont_throw
public void With_valid_arguments_dont_throw()
{
var database = new Database(new Mock<InternalContextForMock>().Object);
var query = database.SqlQuery(typeof(Random), "query");
Assert.NotNull(query);
Assert.Null(query.InternalQuery.Streaming);
}
示例3: With_null_type_throws
public void With_null_type_throws()
{
var database = new Database(new Mock<InternalContextForMock>().Object);
Assert.Equal(
"elementType",
Assert.Throws<ArgumentNullException>(() => database.SqlQuery(null, "query")).ParamName);
}
示例4: With_null_parameters_throws
public void With_null_parameters_throws()
{
var database = new Database(new Mock<InternalContextForMock>().Object);
Assert.Equal(
"parameters",
Assert.Throws<ArgumentNullException>(() => database.SqlQuery(typeof(Random), "query", null)).ParamName);
}
示例5: With_whitespace_SQL_throws
public void With_whitespace_SQL_throws()
{
var database = new Database(new Mock<InternalContextForMock>().Object);
Assert.Equal(
Strings.ArgumentIsNullOrWhitespace("sql"),
Assert.Throws<ArgumentException>(() => database.SqlQuery(typeof(Random), " ")).Message);
}
示例6: Passing_empty_SQL_string_to_non_generic_database_query_method_throws
public void Passing_empty_SQL_string_to_non_generic_database_query_method_throws()
{
var database = new Database(new Mock<InternalContextForMock>().Object);
Assert.Equal(Strings.ArgumentIsNullOrWhitespace("sql"), Assert.Throws<ArgumentException>(() => database.SqlQuery(typeof(Random), "")).Message);
}
示例7: Passing_null_parameters_to_generic_database_query_method_throws
public void Passing_null_parameters_to_generic_database_query_method_throws()
{
var database = new Database(new Mock<InternalContextForMock>().Object);
Assert.Equal("parameters", Assert.Throws<ArgumentNullException>(() => database.SqlQuery<Random>("query", null)).ParamName);
}
示例8: With_valid_arguments_dont_throw
public void With_valid_arguments_dont_throw()
{
var database = new Database(new Mock<InternalContextForMock>().Object);
Assert.NotNull(database.SqlQuery<Random>("query"));
}