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


C# SQLiteConnection.Get方法代码示例

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


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

示例1: GetOptions

 public static Options GetOptions()
 {
     using (SQLiteConnection conn = new SQLiteConnection(dbLocation))
       {
     return conn.Get<Options>(1);
       }
 }
开发者ID:spaceyjase,项目名称:timer,代码行数:7,代码来源:OptionsRepository.cs

示例2: OptionsRepository

 static OptionsRepository()
 {
     // Figure out where the SQLite database will be.
       var documents = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
       dbLocation = Path.Combine(documents, "timer_sqlite-net.db");
       using (SQLiteConnection conn = new SQLiteConnection(dbLocation))
       {
     conn.CreateTable<Options>();
     Options o = null;
     try
     {
       o = conn.Get<Options>(1);
     }
     catch (InvalidOperationException)
     {
       // Doesn't exist...
     }
     if (o == null)
     {
       // Create options... a bit contrived perhaps :)
       o = new Options();
       o.Seconds = 5;
       int rows = conn.Insert(o);
       if (rows == 0)
       {
     throw new InvalidOperationException("Can't create options!");
       }
     }
       }
 }
开发者ID:spaceyjase,项目名称:timer,代码行数:30,代码来源:OptionsRepository.cs

示例3: TestInsertAllAsync

		public void TestInsertAllAsync ()
		{
			// create a bunch of customers...
			List<Customer> customers = new List<Customer> ();
			for (int index = 0; index < 100; index++) {
				Customer customer = new Customer ();
				customer.FirstName = "foo";
				customer.LastName = "bar";
				customer.Email = Guid.NewGuid ().ToString ();
				customers.Add (customer);
			}

			// connect...
			string path = null;
			var conn = GetConnection (ref path);
			conn.CreateTableAsync<Customer> ().Wait ();

			// insert them all...
			conn.InsertAllAsync (customers).Wait ();

			// check...
			using (SQLiteConnection check = new SQLiteConnection (path)) {
				for (int index = 0; index < customers.Count; index++) {
					// load it back and check...
					Customer loaded = check.Get<Customer> (customers[index].Id);
					Assert.AreEqual (loaded.Email, customers[index].Email);
				}
			}
		}
开发者ID:89sos98,项目名称:sqlite-net,代码行数:29,代码来源:AsyncTests.cs

示例4: TestUpdateAsync

		public void TestUpdateAsync ()
		{
			// create...
			Customer customer = CreateCustomer ();

			// connect...
			string path = null;
			var conn = GetConnection (ref path);
			conn.CreateTableAsync<Customer> ().Wait ();

			// run...
			conn.InsertAsync (customer).Wait ();

			// change it...
			string newEmail = Guid.NewGuid ().ToString ();
			customer.Email = newEmail;

			// save it...
			conn.UpdateAsync (customer).Wait ();

			// check...
			using (SQLiteConnection check = new SQLiteConnection (path)) {
				// load it back - should be changed...
				Customer loaded = check.Get<Customer> (customer.Id);
				Assert.AreEqual (newEmail, loaded.Email);
			}
		}
开发者ID:89sos98,项目名称:sqlite-net,代码行数:27,代码来源:AsyncTests.cs

示例5: TestInsertAsync

		public void TestInsertAsync ()
		{
			// create...
			Customer customer = this.CreateCustomer ();

			// connect...
			string path = null;
			var conn = GetConnection (ref path);
			conn.CreateTableAsync<Customer> ().Wait ();

			// run...
			conn.InsertAsync (customer).Wait ();

			// check that we got an id...
			Assert.AreNotEqual (0, customer.Id);

			// check...
			using (SQLiteConnection check = new SQLiteConnection (path)) {
				// load it back...
				Customer loaded = check.Get<Customer> (customer.Id);
				Assert.AreEqual (loaded.Id, customer.Id);
			}
		}
开发者ID:89sos98,项目名称:sqlite-net,代码行数:23,代码来源:AsyncTests.cs

示例6: TestUpdateAsync

        public async Task TestUpdateAsync()
        {
            // create...
            Customer customer = CreateCustomer();

            // connect...
            string path = null;
            SQLiteAsyncConnection conn = GetConnection(ref path);
            await conn.CreateTableAsync<Customer>();

            // run...
            await conn.InsertAsync(customer);

            // change it...
            string newEmail = Guid.NewGuid().ToString();
            customer.Email = newEmail;

            // save it...
            await conn.UpdateAsync(customer);

            // check...
            using (var check = new SQLiteConnection(_sqlite3Platform, path))
            {
                // load it back - should be changed...
                var loaded = check.Get<Customer>(customer.Id);
                Assert.AreEqual(newEmail, loaded.Email);
            }
        }
开发者ID:happynik,项目名称:SQLite.Net-PCL,代码行数:28,代码来源:AsyncTests.cs

示例7: TestInsertAsync

        public async Task TestInsertAsync()
        {
            // create...
            Customer customer = CreateCustomer();

            // connect...
            string path = null;
            SQLiteAsyncConnection conn = GetConnection(ref path);
            await conn.CreateTableAsync<Customer>();

            // run...
            await conn.InsertAsync(customer);

            // check that we got an id...
            Assert.AreNotEqual(0, customer.Id);

            // check...
            using (var check = new SQLiteConnection(_sqlite3Platform, path))
            {
                // load it back...
                var loaded = check.Get<Customer>(customer.Id);
                Assert.AreEqual(loaded.Id, customer.Id);
            }
        }
开发者ID:happynik,项目名称:SQLite.Net-PCL,代码行数:24,代码来源:AsyncTests.cs

示例8: TestInsertOrReplaceAsync

        public async Task TestInsertOrReplaceAsync()
        {
            // create...
            var customer = new Customer();
            customer.Id = 42;
            customer.FirstName = "foo";
            customer.LastName = "bar";
            customer.Email = Guid.NewGuid().ToString();

            // connect...
            string path = null;
            SQLiteAsyncConnection conn = GetConnection(ref path);
            await conn.CreateTableAsync<Customer>();

            // run...
            await conn.InsertOrReplaceAsync(customer);

            // check...
            using (var check = new SQLiteConnection(_sqlite3Platform, path))
            {
                // load it back...
                var loaded = check.Get<Customer>(customer.Id);
                Assert.AreEqual(loaded.Id, customer.Id);
                Assert.AreEqual(loaded.FirstName, customer.FirstName);
                Assert.AreEqual(loaded.LastName, customer.LastName);
                Assert.AreEqual(loaded.Email, customer.Email);
            }

            // change ...
            customer.FirstName = "baz";
            customer.LastName = "biz";
            customer.Email = Guid.NewGuid().ToString();

            // replace...
            await conn.InsertOrReplaceAsync(customer);

            // check again...
            // check...
            using (var check = new SQLiteConnection(_sqlite3Platform, path))
            {
                // load it back...
                var loaded = check.Get<Customer>(customer.Id);
                Assert.AreEqual(loaded.Id, customer.Id);
                Assert.AreEqual(loaded.FirstName, customer.FirstName);
                Assert.AreEqual(loaded.LastName, customer.LastName);
                Assert.AreEqual(loaded.Email, customer.Email);
            }
        }
开发者ID:flowpilots,项目名称:SQLite.Net-PCL,代码行数:48,代码来源:AsyncTests.cs

示例9: TestInsertOrReplaceAllAsync

        public async Task TestInsertOrReplaceAllAsync()
        {
            // create a bunch of customers...
            var customers = new List<Customer>();
            for (int index = 0; index < 100; index++)
            {
                var customer = new Customer();
                customer.Id = index;
                customer.FirstName = "foo";
                customer.LastName = "bar";
                customer.Email = Guid.NewGuid().ToString();
                customers.Add(customer);
            }

            // connect...
            string path = null;
            SQLiteAsyncConnection conn = GetConnection(ref path);
            await conn.CreateTableAsync<Customer>();

            // insert them all...
            await conn.InsertOrReplaceAllAsync(customers);

            // change the existing ones...
            foreach (var customer in customers)
            {
                customer.FirstName = "baz";
                customer.LastName = "biz";
            }

            // ... and add a few more
            for (int index = 100; index < 200; index++)
            {
                var customer = new Customer();
                customer.Id = index;
                customer.FirstName = "foo";
                customer.LastName = "bar";
                customer.Email = Guid.NewGuid().ToString();
                customers.Add(customer);
            }

            // insert them all, replacing the already existing ones
            await conn.InsertOrReplaceAllAsync(customers);

            // check...
            using (var check = new SQLiteConnection(_sqlite3Platform, path))
            {
                for (int index = 0; index < customers.Count; index++)
                {
                    // load it back and check...
                    var loaded = check.Get<Customer>(customers[index].Id);
                    Assert.AreEqual(loaded.FirstName, customers[index].FirstName);
                    Assert.AreEqual(loaded.LastName, customers[index].LastName);
                    Assert.AreEqual(loaded.Email, customers[index].Email);
                }
            }

        }
开发者ID:flowpilots,项目名称:SQLite.Net-PCL,代码行数:57,代码来源:AsyncTests.cs


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