iboxdb的删除问题

一学修行 发布于 2016/09/21 08:58
阅读 166
收藏 0

@iBoxDB 你好,想跟你请教个问题:

我用box.Binder去一次性绑定多个ID记录。然后在事务中删除并提交后,再插入新记录时,提示主键冲突。请问是怎么回事。

加载中
0
0
iBoxDB
iBoxDB

测试正常

class MainClass
	{
		public static void Main (string[] args)
		{
			iBoxDB.LocalServer.DB.Root ("/tmp/");
			iBoxDB.DBDebug.DDebug.DeleteDBFiles (1);
			DB db = new DB (1); 
			db.GetConfig ().EnsureTable<DT> ("DT", "ID");
			AutoBox auto = db.Open ();

			for (int i=0; i<20; i++) {
				long id = auto.NewId (0, 10);

				using (var box = auto.Cube()) {
					for (var j=0; j<10; j++) {
						DT dt = new DT { ID = id+j, Value = "V"+ id + "-" + j };
						box ["DT"].Insert (dt);
					}
					box.Commit ().Assert ();
				}
				Console.WriteLine (i + " insert: " + auto.SelectCount ("from DT"));

				using (var box = auto.Cube()) {
					for (var j=0; j<10; j++) { 
						box ["DT", id + j].Delete ();
					}
					box.Commit ().Assert ();
				}
				Console.WriteLine (i + " delete: " + auto.SelectCount ("from DT"));


				using (var box = auto.Cube()) {
					for (var j=0; j<10; j++) {
						DT dt = new DT { ID = id+j, Value = "V"+ id + "-" + j };
						box ["DT"].Insert (dt);
					}
					box.Commit ().Assert ();
				}
				Console.WriteLine (i + " insert 2: " + auto.SelectCount ("from DT"));
				Console.WriteLine ();
			}

		}
	}

	public class DT
	{
		public long ID;
		public string Value;
	}



返回顶部
顶部