當前位置: 首頁>>代碼示例>>C#>>正文


C# SqlDataAccess.Query方法代碼示例

本文整理匯總了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);
        }
開發者ID:RickStrahl,項目名稱:WestwindToolkit,代碼行數:24,代碼來源:SqlDataAccessTests.cs

示例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.");
        }
開發者ID:RickStrahl,項目名稱:WestwindToolkit,代碼行數:12,代碼來源:SqlDataAccessTests.cs

示例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);
                }
            }
        }
開發者ID:RickStrahl,項目名稱:WestwindToolkit,代碼行數:14,代碼來源:SqlDataAccessTests.cs

示例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");
     }
 }
開發者ID:RickStrahl,項目名稱:WestwindToolkit,代碼行數:19,代碼來源:SqlDataAccessTests.cs

示例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);
         }
     }
 }
開發者ID:RickStrahl,項目名稱:WestwindToolkit,代碼行數:18,代碼來源:SqlDataAccessTests.cs

示例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");
     }
 }
開發者ID:RickStrahl,項目名稱:WestwindToolkit,代碼行數:22,代碼來源:SqlDataAccessTests.cs

示例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);
        }
開發者ID:RickStrahl,項目名稱:WestwindToolkit,代碼行數:18,代碼來源:SqlDataAccessTests.cs


注:本文中的Westwind.Utilities.Data.SqlDataAccess.Query方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。