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


C# OrmTestSession.Insert方法代码示例

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


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

示例1: ClearTableTest

        public void ClearTableTest()
        {
            // setup
            var db = new OrmTestSession();
            db.CreateTable<Product>();

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

            // confirm
            Assert.AreEqual(2, db.Table<Product>().Count());
            db.Get<Product>(1);

            // clear
            Assert.AreEqual(2, db.ClearTable<Product>());

            // confirm
            Assert.AreEqual(0, db.Table<Product>().Count());

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

            // confirm that the Ids have not reset
            Assert.AreEqual(1, db.Table<Product>().Count());
            db.Get<Product>(3);
        }
开发者ID:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:27,代码来源:DropTableTest.cs

示例2: Collate

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

            var db = new OrmTestSession();
            db.CreateTable<TestObj>();
            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:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:34,代码来源:CollateTest.cs

示例3: TestBoolean

        public void TestBoolean()
        {
            var db = new OrmTestSession();
            db.CreateTable<Vo>();

            for (int i = 0; i < 10; i++)
            {
                db.Insert(new Vo {Flag = (i%3 == 0), Text = String.Format("VO{0}", i)});
            }

            // count vo which flag is true            
            Assert.AreEqual(4, CountWithFlag(db, true));
            Assert.AreEqual(6, CountWithFlag(db, false));

            Debug.WriteLine("VO with true flag:");
            foreach (Vo vo in db.Query<Vo>("SELECT * FROM VO Where Flag = ?", true))
            {
                Debug.WriteLine(vo.ToString());
            }

            Debug.WriteLine("VO with false flag:");
            foreach (Vo vo in db.Query<Vo>("SELECT * FROM VO Where Flag = ?", false))
            {
                Debug.WriteLine(vo.ToString());
            }
        }
开发者ID:distributedlife,项目名称:Mono.Data.Sqlite.Orm,代码行数:26,代码来源:BooleanTest.cs

示例4: CreateInsertDrop

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

            db.CreateTable<Product>();

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

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

            Assert.AreEqual(1, n);

            db.DropTable<Product>();

            try
            {
                // Should throw SqliteException
                db.Table<Product>().Count();

                Assert.Fail("Expeced 'table does not exist' error.");
            }
            catch (SqliteException)
            {
            }
            catch
            {
                Assert.Fail();
            }
        }
开发者ID:distributedlife,项目名称:Mono.Data.Sqlite.Orm,代码行数:33,代码来源:DropTableTest.cs

示例5: StringQueryOnQueryableTable

        public void StringQueryOnQueryableTable()
        {
            using (var db = new OrmTestSession())
            {
                db.CreateTable<QueryableTable>();
                db.Insert(new QueryableTable { Name = "sqlite" });
                db.Insert(new QueryableTable { Name = "sqlevy" });
                db.Insert(new QueryableTable { Name = "cars" });
                db.Insert(new QueryableTable { Name = "we know sqlite is cool" });
                db.Insert(new QueryableTable { Name = "we think sqlites" });

                var count = db.ExecuteScalar<int>(
                    "SELECT COUNT(*) FROM [QueryableTable] WHERE [Name] MATCH ?", 
                    "sqlite");

                Assert.AreEqual(3, count);
            }
        }
开发者ID:distributedlife,项目名称:Mono.Data.Sqlite.Orm,代码行数:18,代码来源:CreateVirtualTableTest.cs

示例6: CreateInstanceHookTestNonGeneric

 public void CreateInstanceHookTestNonGeneric()
 {
     var db = new OrmTestSession();
     db.InstanceCreated += InstanceCreated;
     db.CreateTable<HookTestTable>();
     db.Insert(new HookTestTable { Text = InsertedTest });
     var got = db.Get(typeof(HookTestTable), 1);
     Assert.AreEqual(ReplacedText, ((HookTestTable)got).Text);
 }
开发者ID:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:9,代码来源:HooksTest.cs

示例7: CreateInstanceHookTest

 public void CreateInstanceHookTest()
 {
     var db = new OrmTestSession();
     db.InstanceCreated += InstanceCreated;
     db.CreateTable<HookTestTable>();
     db.Insert(new HookTestTable { Text = InsertedTest });
     var got = db.Get<HookTestTable>(1);
     Assert.AreEqual(ReplacedText, got.Text);
 }
开发者ID:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:9,代码来源:HooksTest.cs

示例8: IntegrityCheckTest

 public void IntegrityCheckTest()
 {
     using (var db = new OrmTestSession())
     {
         db.CreateTable<SimpleTable>();
         db.Insert(new SimpleTable { Name = RandomString() });
         db.IntegrityCheck<SimpleTable>();
     }
 }
开发者ID:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:9,代码来源:FTSSpecialCommandsTest.cs

示例9: MergeTest

 public void MergeTest()
 {
     using (var db = new OrmTestSession())
     {
         db.CreateTable<SimpleTable>();
         db.Insert(new SimpleTable { Name = RandomString() });
         db.Merge<SimpleTable>();
     }
 }
开发者ID:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:9,代码来源:FTSSpecialCommandsTest.cs

示例10: RunMergeUntilOptimalTest

 public void RunMergeUntilOptimalTest()
 {
     using (var db = new OrmTestSession())
     {
         db.CreateTable<SimpleTable>();
         db.Insert(new SimpleTable { Name = RandomString() });
         db.RunMergeUntilOptimal<SimpleTable>();
     }
 }
开发者ID:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:9,代码来源:FTSSpecialCommandsTest.cs

示例11: Insert

        public void Insert()
        {
            var db = new OrmTestSession();
            db.CreateTable<Product>();

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

            var p = db.Get<Product>(1);

            Assert.AreEqual(TestString, p.Name);
        }
开发者ID:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:11,代码来源:UnicodeTest.cs

示例12: CreateThem

        public void CreateThem()
        {
            var db = new OrmTestSession();
            db.CreateTable<Product>();
            db.CreateTable<OrderLine>();

            var foo = new Product { Name = "Foo", Price = 10.0m };
            var bar = new Product { Name = "Bar", Price = 0.10m };
            db.Insert(foo);
            db.Insert(bar);
            db.Insert(new OrderLine { ProductId = foo.Id, Quantity = 6, UnitPrice = 10.01m });
            db.Insert(new OrderLine { ProductId = foo.Id, Quantity = 3, UnitPrice = 0.02m });
            db.Insert(new OrderLine { ProductId = bar.Id, Quantity = 9, UnitPrice = 100.01m });

            OrderLine[] lines = foo.OrderLines;

            Assert.AreEqual(lines.Length, 2, "Has 2 order lines");
            Assert.AreEqual(foo.Connection, db, "foo.Connection was set");
            Assert.AreEqual(lines[0].Connection, db, "lines[0].Connection was set");
        }
开发者ID:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:20,代码来源:ConnectionTrackingTest.cs

示例13: Query

        public void Query()
        {
            var db = new OrmTestSession();
            db.CreateTable<Product>();

            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:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:12,代码来源:UnicodeTest.cs

示例14: InterfaceTest

        public void InterfaceTest()
        {
            var db = new OrmTestSession();

            db.CreateTable<Product>();

            var obj1 = new Product { Name = "Some Cool Name" };

            int numIn1 = db.Insert(obj1);
            Assert.AreEqual(1, numIn1);

            db.Close();
        }
开发者ID:mattleibow,项目名称:Mono.Data.Sqlite.Orm,代码行数:13,代码来源:InterfaceTests.cs

示例15: StringContains

        public void StringContains()
        {
            var db = new OrmTestSession();
            db.CreateTable<TestObj>();

            var testObj = new TestObj { Name = "This is a Good name" };
            db.Insert(testObj);

            var stringContainsTest = (from n in db.Table<TestObj>() where n.Name.Contains("Good") select n).Single();
            Assert.AreEqual(testObj.Id, stringContainsTest.Id);
            var finder = "good";
            stringContainsTest = (from n in db.Table<TestObj>() where n.Name.Contains(finder) select n).Single();
            Assert.AreEqual(testObj.Id, stringContainsTest.Id);
        }
开发者ID:distributedlife,项目名称:Mono.Data.Sqlite.Orm,代码行数:14,代码来源:ContainsTest.cs


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