本文整理汇总了C#中Westwind.Utilities.Data.SqlDataAccess.Query方法的典型用法代码示例。如果您正苦于以下问题:C# SqlDataAccess.Query方法的具体用法?C# SqlDataAccess.Query怎么用?C# SqlDataAccess.Query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Westwind.Utilities.Data.SqlDataAccess
的用法示例。
在下文中一共展示了SqlDataAccess.Query方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: QueryToIEnumerableTest
public void QueryToIEnumerableTest()
{
SqlDataAccess data = new SqlDataAccess(STR_ConnectionString);
var swatch = new Stopwatch();
swatch.Start();
var enumerable = data.Query<WebLogEntry>("select * from ApplicationLog");
var recs = new List<WebLogEntry>();
foreach (var entry in enumerable)
{
recs.Add(entry);
}
swatch.Stop();
Assert.IsNotNull(recs, "Null");
Assert.IsTrue(recs.Count > 0, "Count < 1");
Assert.IsTrue(recs[0].Entered > DateTime.MinValue);
Console.WriteLine(swatch.ElapsedMilliseconds);
Console.WriteLine(recs.Count);
}
示例2: QueryWithNoMatchingDataTest
public void QueryWithNoMatchingDataTest()
{
SqlDataAccess data = new SqlDataAccess(STR_ConnectionString);
// no records returned from query
var entries = data.Query<WebLogEntry>("select * from ApplicationLog where 1=2");
var ent = entries.ToList();
Console.WriteLine(ent.Count);
Assert.IsNotNull(entries, "IEnumerable should not be null - only null on failure.");
}
示例3: QueryToCustomer
public void QueryToCustomer()
{
using (var data = new SqlDataAccess(STR_ConnectionString))
{
var custList = data.Query<Customer>("select * from customers where LastName like @0", "S%");
Assert.IsNotNull(custList, data.ErrorMessage);
foreach (var customer in custList)
{
Console.WriteLine(customer.Company + " " + customer.Entered);
}
}
}
示例4: QueryTest
public void QueryTest()
{
using (var data = new SqlDataAccess(STR_ConnectionString))
{
var swatch = Stopwatch.StartNew();
var logEntries =
data.Query<WebLogEntry>(
"select * from ApplicationLog where entered > @0 and entered < @1 order by Entered",
DateTime.Now.AddYears(-115), DateTime.Now.AddYears(-1)).ToList();
Assert.IsNotNull(logEntries, data.ErrorMessage);
Console.WriteLine(logEntries.Count);
foreach (var logEntry in logEntries)
{
Console.WriteLine(logEntry.Entered);
}
swatch.Stop();
Console.WriteLine(swatch.ElapsedMilliseconds + "ms");
}
}
示例5: QueryException
public void QueryException()
{
using (var data = new SqlDataAccess(STR_ConnectionString)
{
ThrowExceptions = true
})
{
try
{
var logEntries = data.Query<WebLogEntry>("select * from ApplicationLogggg");
Assert.Fail("Invalid Sql Statement should not continue");
}
catch (Exception ex)
{
Console.WriteLine("Error caught correctly: " + ex.Message);
}
}
}
示例6: NewParametersExecuteEntityTest
public void NewParametersExecuteEntityTest()
{
using (var data = new SqlDataAccess(STR_ConnectionString))
{
//var cmd = data.CreateCommand("select * from ApplicationLog where entered > @0 and entered > @1",CommandType.Text, DateTime.Now.AddYears(-10), DateTime.Now.AddYears(-));
//var table = data.ExecuteTable("TLogs", cmd);
var swatch = Stopwatch.StartNew();
var entries =
data.Query<WebLogEntry>(
"select * from ApplicationLog where entered > @0 and entered < @1 order by Entered",
DateTime.Now.AddYears(-115), DateTime.Now.AddYears(-1));
var logEntries = entries.ToList();
Assert.IsNotNull(logEntries, data.ErrorMessage);
Console.WriteLine(logEntries.Count);
foreach (var logEntry in logEntries)
{
Console.WriteLine(logEntry.Entered);
}
swatch.Stop();
Console.WriteLine(swatch.ElapsedMilliseconds + "ms");
}
}
示例7: ExecuteDataReaderToListTest
public void ExecuteDataReaderToListTest()
{
SqlDataAccess data = new SqlDataAccess(STR_ConnectionString);
var swatch = new Stopwatch();
swatch.Start();
var recs = data.Query<WebLogEntry>("select * from ApplicationLog").ToList();
swatch.Stop();
Assert.IsNotNull(recs, "Null");
Assert.IsTrue(recs.Count > 0, "Count < 1");
Assert.IsTrue(recs[0].Entered > DateTime.MinValue);
Console.WriteLine(swatch.ElapsedMilliseconds);
Console.WriteLine(recs.Count);
}