当前位置: 首页>>代码示例>>C#>>正文


C# TestDb.Table方法代码示例

本文整理汇总了C#中SQLite.Tests.TestDb.Table方法的典型用法代码示例。如果您正苦于以下问题:C# TestDb.Table方法的具体用法?C# TestDb.Table怎么用?C# TestDb.Table使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SQLite.Tests.TestDb的用法示例。


在下文中一共展示了TestDb.Table方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ContainsQueriedData

        public void ContainsQueriedData()
        {
            int n = 20;
            var cq =from i in Enumerable.Range(1, n)
                    select new TestObj() {
                Name = i.ToString()
            };

            var db = new TestDb(Path.GetTempFileName());

            db.InsertAll(cq);

            db.Trace = true;

            var tensq = new string[] { "0", "10", "20" };
            var tens = (from o in db.Table<TestObj>() where tensq.Contains(o.Name) select o).ToList();
            Assert.AreEqual(2, tens.Count);

            var moreq = new string[] { "0", "x", "99", "10", "20", "234324" };
            var more = (from o in db.Table<TestObj>() where moreq.Contains(o.Name) select o).ToList();
            Assert.AreEqual(2, more.Count);

            // https://github.com/praeclarum/sqlite-net/issues/28
            var moreq2 = moreq.ToList ();
            var more2 = (from o in db.Table<TestObj>() where moreq2.Contains(o.Name) select o).ToList();
            Assert.AreEqual(2, more2.Count);
        }
开发者ID:Toshik,项目名称:sqlite-net,代码行数:27,代码来源:ContainsTest.cs

示例2: Skip

        public void Skip()
        {
            var n = 100;

            var cq =	from i in Enumerable.Range(1, n)
                    select new TestObj() {
                Order = i
            };
            var objs = cq.ToArray();
            var db = new TestDb(TestPath.GetTempFileName());

            var numIn = db.InsertAll(objs);
            Assert.AreEqual(numIn, n, "Num inserted must = num objects");

            var q = from o in db.Table<TestObj>()
                    orderby o.Order
                    select o;

            var qs1 = q.Skip(1);
            var s1 = qs1.ToList();
            Assert.AreEqual(n - 1, s1.Count);
            Assert.AreEqual(2, s1[0].Order);

            var qs5 = q.Skip(5);
            var s5 = qs5.ToList();
            Assert.AreEqual(n - 5, s5.Count);
            Assert.AreEqual(6, s5[0].Order);
        }
开发者ID:aussieman9,项目名称:sqlite-net,代码行数:28,代码来源:SkipTest.cs

示例3: CreateDbWithOne2Many

		SQLiteConnection CreateDbWithOne2Many ()
		{
			var db = new TestDb ()
				.SetForeignKeysPermissions(true);
			db.CreateTable<TestObjWithOne2Many> ();
			db.CreateTable<TestDependentObj> ();
			var items = Enumerable.Range(1,parentCount)
							.Select(i => new TestObjWithOne2Many {Id = i, 
																  ObjList = Enumerable.Range(1,childCount)
																	.Select(x => new TestDependentObj{OwnerId = i})
																										.ToList()}).ToList();
			db.InsertAll (items);
			Assert.AreEqual (parentCount, db.Table<TestObjWithOne2Many> ().Count ());
			Assert.AreEqual (parentCount * childCount , db.Table<TestDependentObj> ().Count ());
			return db;
		}
开发者ID:snvector,项目名称:sqlite-net,代码行数:16,代码来源:DeleteTest.cs

示例4: Issue86

		public void Issue86 ()
		{
			var db = new TestDb ();
			db.CreateTable<Foo> ();

			db.Insert (new Foo { Bar = 42 } );
			db.Insert (new Foo { Bar = 69 } );

			var found42 = db.Table<Foo> ().Where (f => f.Bar == 42).FirstOrDefault();
			Assert.IsNotNull (found42);

			var ordered = new List<Foo>(db.Table<Foo>().OrderByDescending(f => f.Bar));
			Assert.AreEqual(2, ordered.Count);
			Assert.AreEqual(69, ordered[0].Bar);
			Assert.AreEqual(42, ordered[1].Bar);
		}
开发者ID:89sos98,项目名称:sqlite-net,代码行数:16,代码来源:MappingTest.cs

示例5: CreateDb

		SQLiteConnection CreateDb ()
		{
			var db = new TestDb ();
			db.CreateTable<TestTable> ();
			var items = from i in Enumerable.Range (0, Count)
				select new TestTable { Datum = 1000+i };
			db.InsertAll (items);
			Assert.AreEqual (Count, db.Table<TestTable> ().Count ());
			return db;
		}
开发者ID:89sos98,项目名称:sqlite-net,代码行数:10,代码来源:DeleteTest.cs

示例6: CreateInsertDrop

        public void CreateInsertDrop()
        {
            var db = new TestDb ();

            db.CreateTable<Product> ();

            db.Insert (new Product {
                Name = "Hello",
                Price = 16,
            });

            var n = db.Table<Product> ().Count ();

            Assert.AreEqual (1, n);

            db.DropTable<Product> ();

            ExceptionAssert.Throws<SQLiteException>(() => db.Table<Product> ().Count ());
        }
开发者ID:runegri,项目名称:sqlite-net,代码行数:19,代码来源:DropTableTest.cs

示例7: CreateInsertDrop

        public void CreateInsertDrop()
        {
            var db = new TestDb ();

            db.CreateTable<Product> ();

            db.Insert (new Product {
                Name = "Hello",
                Price = 16,
            });

            var n = db.Table<Product> ().Count ();

            Assert.AreEqual (1, n);

            db.DropTable<Product> ();

            db.Table<Product> ().Count (); // Should throw
        }
开发者ID:chaosnhatred,项目名称:sqlite-net,代码行数:19,代码来源:DropTableTest.cs

示例8: VerifyCreations

        private static void VerifyCreations(TestDb db)
        {
            var orderLine = db.GetMapping(typeof(OrderLine));
            Assert.AreEqual(6, orderLine.Columns.Length);

            var l = new OrderLine()
            {
                Status = OrderLineStatus.Shipped
            };
            db.Insert(l);
            var lo = db.Table<OrderLine>().First(x => x.Status == OrderLineStatus.Shipped);
            Assert.AreEqual(lo.Id, l.Id);
        }
开发者ID:golddragon007,项目名称:sqlite-net,代码行数:13,代码来源:CreateTableTest.cs

示例9: ContainsConstantData

        public void ContainsConstantData()
        {
            int n = 20;
            var cq =from i in Enumerable.Range(1, n)
                    select new TestObj() {
                Name = i.ToString()
            };

            var db = new TestDb(Path.GetTempFileName());

            db.InsertAll(cq);

            db.Trace = true;

            var tensq = new string[] { "0", "10", "20" };
            var tens = (from o in db.Table<TestObj>() where tensq.Contains(o.Name) select o).ToList();
            Assert.AreEqual(2, tens.Count);

            var moreq = new string[] { "0", "x", "99", "10", "20", "234324" };
            var more = (from o in db.Table<TestObj>() where moreq.Contains(o.Name) select o).ToList();
            Assert.AreEqual(2, more.Count);
        }
开发者ID:Toshik,项目名称:sqlite-net,代码行数:22,代码来源:ContainsTest.cs

示例10: Query

        public void Query()
        {
            var db = new TestDb ();

            db.CreateTable<Product> ();

            string testString = "\u2329\u221E\u232A";

            db.Insert (new Product {
                Name = testString,
            });

            var ps = (from p in db.Table<Product> () where p.Name == testString select p).ToList ();

            Assert.AreEqual (1, ps.Count);
            Assert.AreEqual (testString, ps [0].Name);
        }
开发者ID:chaosnhatred,项目名称:sqlite-net,代码行数:17,代码来源:UnicodeTest.cs

示例11: Issue115_MissingPrimaryKey

        public void Issue115_MissingPrimaryKey()
        {
            using (var conn = new TestDb ()) {

                conn.CreateTable<Issue115_MyObject> ();
                conn.InsertAll (from i in Enumerable.Range (0, 10) select new Issue115_MyObject {
                    UniqueId = i.ToString (),
                    OtherValue = (byte)(i * 10),
                });

                var query = conn.Table<Issue115_MyObject> ();
                foreach (var itm in query) {
                    itm.OtherValue++;
                    Assert.AreEqual (1, conn.Update (itm, typeof(Issue115_MyObject)));
                }
            }
        }
开发者ID:robertgreen,项目名称:sqlite-net,代码行数:17,代码来源:CreateTableTest.cs

示例12: CreateThem

        public void CreateThem()
        {
            var db = new TestDb ();

            db.CreateTable<Product> ();
            db.CreateTable<Order> ();
            db.CreateTable<OrderLine> ();
            db.CreateTable<OrderHistory> ();

            var orderLine = db.GetMapping(typeof(OrderLine));
            Assert.AreEqual(6, orderLine.Columns.Length, "Order history has 3 columns");

            var l = new OrderLine() {
                Status = OrderLineStatus.Shipped
            };
            db.Insert(l);
            var lo = db.Table<OrderLine>().Where(x => x.Status == CreateTableTest.OrderLineStatus.Shipped).FirstOrDefault();
            Assert.AreEqual(lo.Id, l.Id);
        }
开发者ID:Ngugi1,项目名称:sqlite-net,代码行数:19,代码来源:CreateTableTest.cs

示例13: Collate

        public void Collate()
        {
            var obj = new TestObj()
            {
                CollateDefault = "Alpha ",
                CollateBinary = "Alpha ",
                CollateRTrim = "Alpha ",
                CollateNoCase = "Alpha ",
            };

            var db = new TestDb(TestPath.GetTempFileName());

            db.Insert(obj);

            Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateDefault == "Alpha " select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateDefault == "ALPHA " select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateDefault == "Alpha" select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateDefault == "ALPHA" select o).Count());

            Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateBinary == "Alpha " select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateBinary == "ALPHA " select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateBinary == "Alpha" select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateBinary == "ALPHA" select o).Count());

            Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateRTrim == "Alpha " select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateRTrim == "ALPHA " select o).Count());
            Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateRTrim == "Alpha" select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateRTrim == "ALPHA" select o).Count());

            Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateNoCase == "Alpha " select o).Count());
            Assert.AreEqual(1, (from o in db.Table<TestObj>() where o.CollateNoCase == "ALPHA " select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateNoCase == "Alpha" select o).Count());
            Assert.AreEqual(0, (from o in db.Table<TestObj>() where o.CollateNoCase == "ALPHA" select o).Count());
        }
开发者ID:Banane9,项目名称:sqlite-net,代码行数:34,代码来源:CollateTest.cs

示例14: Issue303_WhereNot_B

        public void Issue303_WhereNot_B()
        {
            using (var db = new TestDb())
            {
                db.CreateTable<Issue303_B>();
                db.Insert(new Issue303_B { Id = 1, Flag = true });
                db.Insert(new Issue303_B { Id = 2, Flag = false });
                db.Insert(new Issue303_B { Id = 3, Flag = true });
                db.Insert(new Issue303_B { Id = 4, Flag = false });

                var r = (from p in db.Table<Issue303_B>() where !p.Flag select p).ToList();
                Assert.AreEqual(2, r.Count);
                Assert.AreEqual(2, r[0].Id);
                Assert.AreEqual(4, r[1].Id);
            }
        }
开发者ID:FatJohn,项目名称:sqlite-net,代码行数:16,代码来源:LinqTest.cs

示例15: Issue303_WhereNot_A

        public void Issue303_WhereNot_A()
        {
            using (var db = new TestDb())
            {
                db.CreateTable<Issue303_A>();
                db.Insert(new Issue303_A { Id = 1, Name = "aa" });
                db.Insert(new Issue303_A { Id = 2, Name = null });
                db.Insert(new Issue303_A { Id = 3, Name = "test" });
                db.Insert(new Issue303_A { Id = 4, Name = null });

                var r = (from p in db.Table<Issue303_A>() where !(p.Name == null) select p).ToList();
                Assert.AreEqual(2, r.Count);
                Assert.AreEqual(1, r[0].Id);
                Assert.AreEqual(3, r[1].Id);
            }
        }
开发者ID:FatJohn,项目名称:sqlite-net,代码行数:16,代码来源:LinqTest.cs


注:本文中的SQLite.Tests.TestDb.Table方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。