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


C# TestDb.InsertAll方法代码示例

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


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

示例1: SetUp

        public void SetUp()
        {
            _db = new TestDb();
            _db.CreateTable<Product>();
            _db.CreateTable<Order>();
            _db.CreateTable<OrderLine>();

            var p1 = new Product { Name = "One", };
            var p2 = new Product { Name = "Two", };
            var p3 = new Product { Name = "Three", };
            _db.InsertAll(new[] { p1, p2, p3 });

            var o1 = new Order { PlacedTime = DateTime.Now, };
            var o2 = new Order { PlacedTime = DateTime.Now, };
            _db.InsertAll(new[] { o1, o2 });

            _db.InsertAll(new[] {
                new OrderLine {
                    OrderId = o1.Id,
                    ProductId = p1.Id,
                    Quantity = 1,
                },
                new OrderLine {
                    OrderId = o1.Id,
                    ProductId = p2.Id,
                    Quantity = 2,
                },
                new OrderLine {
                    OrderId = o2.Id,
                    ProductId = p3.Id,
                    Quantity = 3,
                },
            });
        }
开发者ID:Banane9,项目名称:sqlite-net,代码行数:34,代码来源:JoinTest.cs

示例2: InsertALot

        public void InsertALot()
        {
            int n = 100000;
            var q =	from i in Enumerable.Range(1, n)
                    select new TestObj() {
                Text = "I am"
            };
            var objs = q.ToArray();
            var db = new TestDb(Path.GetTempFileName());
            db.Trace = false;

            var sw = new Stopwatch();
            sw.Start();

            var numIn = db.InsertAll(objs);

            sw.Stop();

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

            var inObjs = db.CreateCommand("select * from TestObj").ExecuteQuery<TestObj>().ToArray();

            for (var i = 0; i < inObjs.Length; i++) {
                Assert.AreEqual(i+1, objs[i].Id);
                Assert.AreEqual(i+1, inObjs[i].Id);
                Assert.AreEqual("I am", inObjs[i].Text);
            }

            var numCount = db.CreateCommand("select count(*) from TestObj").ExecuteScalar<int>();

            Assert.AreEqual(numCount, n, "Num counted must = num objects");
        }
开发者ID:Ngugi1,项目名称:sqlite-net,代码行数:32,代码来源:InsertTest.cs

示例3: 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

示例4: Setup

        public void Setup()
        {
            testObjects = Enumerable.Range(1, 20).Select(i => new TestObj()).ToList();

            db = new TestDb(TestPath.GetTempFileName());
            db.InsertAll(testObjects);
        }
开发者ID:Banane9,项目名称:sqlite-net,代码行数:7,代码来源:TransactionTest.cs

示例5: 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

示例6: 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

示例7: SetUp

		public void SetUp ()
		{
			db = new TestDb ();
			db.CreateTable<Product> ();
			
			var prods = new[] {
				new Product { Name = "Foo" },
				new Product { Name = "Bar" },
				new Product { Name = "Foobar" },
			};
			
			db.InsertAll (prods);
		}
开发者ID:golddragon007,项目名称:sqlite-net,代码行数:13,代码来源:StringQueryTest.cs

示例8: 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

示例9: 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

示例10: SetUp

		public void SetUp ()
		{
			db = new TestDb ();
			db.Trace = true;
			db.CreateTable<Product> ();
			db.CreateTable<Order> ();
			db.InsertAll (from i in Enumerable.Range (0, 22)
				select new Product { Name = "Thing" + i, Price = (decimal)Math.Pow (2, i) });

			changeCount = 0;

			db.TableChanged += (sender, e) => {

				if (e.Table.TableName == "Product") {
					changeCount++;
				}
			};
		}
开发者ID:89sos98,项目名称:sqlite-net,代码行数:18,代码来源:TableChangedTest.cs

示例11: 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


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