本文整理汇总了C#中DBHelper.Query方法的典型用法代码示例。如果您正苦于以下问题:C# DBHelper.Query方法的具体用法?C# DBHelper.Query怎么用?C# DBHelper.Query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBHelper
的用法示例。
在下文中一共展示了DBHelper.Query方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: QueryTest
public void QueryTest()
{
// Arrange-测试设置,创建对象
DBHelper db = new DBHelper();
Customer customer = new Customer()
{
UserName = "User-1",
Password = "PWDHASH-1 ",
Email = "EMAIL-1 ",
PhoneNumber = "PHONE-1 ",
IsFirstTimeLogin = false,
AccessFailedCount = 0,
CreationDate = DateTime.Now,
IsActive = false
};
int count = 0;
List<Customer> customerList = new List<Customer>();
// 拼接字符串的时候要注意标量的名字要与类中的成员变量名一样(可忽略字母的大小写)
// 例如:此处sql中的@Password中的Password就必须与Customer类中的成员变量Password名称一样(可忽略大小写)
string querySQL = @"SELECT * FROM dbo.CICUser WHERE [email protected] AND [email protected]";
// Act-测试行为,使用功能
customerList = db.Query<Customer>(querySQL, customer).ToList();
count = customerList.Count;
// Assert-测试结果,验证结果
Assert.AreEqual(1,count);
}
示例2: QueryTest
public void QueryTest()
{
// arrange
DBHelper.Sqldb dbType = DBHelper.Sqldb.OrderWrite;
DBHelper db = new DBHelper();
string sql = "SELECT * FROM DealerServiceLog ";
var list = db.Query(sql).ToList();
var log = db.Query<DealerServiceLog>(21);
log.Description = "新增测试用例!!!";
db.Update(log);
// act
int count = list.Count;
// assert
Assert.AreEqual(7, count);
}
示例3: QueryManyTest
public void QueryManyTest()
{
// arrange
DBHelper db = new DBHelper();
string sql = "select CompanyName,CityId,CityName,Balance,Margin,PreDeposits,DealerClass,Partner_CompanyExtent.Score,OrderAmount,ContractAmount,Partner_CompanyExtent.[Status],SolutionIDs,DealerDistrict from Partner_Company,Partner_CompanyExtent where Partner_CompanyExtent.DealerID=Partner_Company.ID";
sql = "SELECT * FROM DealerClassConfig AS D JOIN DealerClassConfig AS D1 ON D.id = D1.ID ";
var list = db.Query(sql).ToList();
// act
int count = list.Count;
var first = (IDictionary<string, object>)list.FirstOrDefault();
// assert
Assert.AreEqual(3, count);
}
示例4: InsertLogTest
public void InsertLogTest()
{
// arrange
DBHelper.Sqldb db = DBHelper.Sqldb.OrderWrite;
DBHelper helper = new DBHelper((int)db);
string sql = "SELECT * FROM DealerClassConfig AS D JOIN DealerClassConfig AS D1 ON D.id = D1.ID ";
var list = helper.Query(sql).ToList();
// act
int count = list.Count;
var first = (IDictionary<string, object>)list.FirstOrDefault();
// assert
Assert.AreEqual(3, count);
}
示例5: RunJsonTest
public void RunJsonTest()
{
DBHelper db = new DBHelper((int)DBHelper.Sqldb.OrderReadOnly);
StringBuilder sql = new StringBuilder();
sql.Append(" SELECT * FROM dbo.C_PageViewLog ");
sql.Append(" WHERE Token IS NOT NULL AND ");
sql.Append(" CreateTime BETWEEN '2015-11-27' AND '2015-12-08' ");
sql.Append(" AND ( ");
// 1018知识列表页;1019论坛列表页;1020问答列表页
sql.Append(" PageView LIKE '%1018%' ");
sql.Append(" OR PageView LIKE '%1019%' ");
sql.Append(" OR PageView LIKE '%1020%' ");
sql.Append(" ) ");
IEnumerable<C_PageViewLog> resultList = db.Query<C_PageViewLog>(sql.ToString());
IDictionary<string, PageViewLogParser> dictionary = new Dictionary<string, PageViewLogParser>();
int count = 1;
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
Console.WriteLine("开始插入本地数据库");
//foreach (var item in resultList)
//{
// db.SwitchDB(DBHelper.Sqldb.UserReadOnly);
// db.AddWithID(item);
//}
Console.WriteLine("插入本地数据库完成");
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:000}",
ts.Hours, ts.Minutes, ts.Seconds,
ts.Milliseconds);
Console.WriteLine("RunTime " + elapsedTime);
stopWatch.Start();
foreach (var res in resultList)
{
PageViewLogParser jParser = new PageViewLogParser(res.PageView);
if (!dictionary.ContainsKey(res.Token))
{
dictionary.Add(res.Token, jParser);
}
else
{
dictionary[res.Token].JsonTextAppend(res.PageView);
}
}
Console.WriteLine(dictionary.Count);
stopWatch.Stop();
ts = stopWatch.Elapsed;
elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:000}",
ts.Hours, ts.Minutes, ts.Seconds,
ts.Milliseconds);
Console.WriteLine("RunTime " + elapsedTime);
stopWatch.Start();
foreach (var item in dictionary)
{
item.Value.Perform();
}
stopWatch.Stop();
ts = stopWatch.Elapsed;
elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:000}",
ts.Hours, ts.Minutes, ts.Seconds,
ts.Milliseconds);
Console.WriteLine("RunTime " + elapsedTime);
stopWatch.Start();
// 知识列表数
int knowledgeCount = dictionary.Count(o => o.Value.knowledgeAccess == true);
int forumCount = dictionary.Count(o => o.Value.forumAccess == true);
int QACount = dictionary.Count(o => o.Value.QAAccess == true);
int kfCount = dictionary.Count(o => o.Value.kfAccess == true);
int fqCount = dictionary.Count(o => o.Value.fqAccess == true);
int kqCount = dictionary.Count(o => o.Value.kqAccess == true);
int kfqCount = dictionary.Count(o => o.Value.kfqAccess == true);
stopWatch.Stop();
ts = stopWatch.Elapsed;
elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:000}",
ts.Hours, ts.Minutes, ts.Seconds,
ts.Milliseconds);
Console.WriteLine("RunTime " + elapsedTime);
Console.WriteLine("知识:\t" + knowledgeCount);
Console.WriteLine("论坛:\t" + forumCount);
Console.WriteLine("问答:\t" + QACount);
Console.WriteLine("同时访问知识和论坛:\t" + kfCount);
Console.WriteLine("同时访问论坛和问答:\t" + fqCount);
Console.WriteLine("同时访问知识和问答:\t" + kqCount);
Console.WriteLine("同时访问三者:\t" + kfqCount);
}