/// <summary> /// 测试 AUTO_INCREMENT 在系统中,是否会影响 EF 的运作。 /// </summary> public static void DoTest() { using (TestEntities context = new TestEntities()) { Console.WriteLine(); Console.WriteLine("测试 AUTO_INCREMENT Start!"); Console.WriteLine("首先测试 执行插入处理!"); try { test_auto_increment_tab test1 = new test_auto_increment_tab() { value = "测试" }; context.test_auto_increment_tab.AddObject(test1); context.SaveChanges(); Console.WriteLine("执行插入成功!"); Console.WriteLine("数据库那里产生了自增的 AUTO_INCREMENT 数值, 同时更新到当前这个字段上."); Console.WriteLine("test1 的 id = {0}", test1.id); Console.WriteLine("尝试再检索."); var query = from data in context.test_auto_increment_tab where data.value == "测试" select data; foreach (test_auto_increment_tab t in query) { Console.WriteLine("id = {0}; value = {1} ", t.id, t.value); context.test_auto_increment_tab.DeleteObject(t); } context.SaveChanges(); Console.WriteLine("执行删除成功!"); } catch (Exception ex) { Console.WriteLine("执行失败!"); Console.WriteLine(ex.Message); } Console.WriteLine("测试 AUTO_INCREMENT Finish!"); Console.WriteLine(); } }
/// <summary> /// 创建新的 test_auto_increment_tab 对象。 /// </summary> /// <param name="id">id 属性的初始值。</param> public static test_auto_increment_tab Createtest_auto_increment_tab(global::System.Int32 id) { test_auto_increment_tab test_auto_increment_tab = new test_auto_increment_tab(); test_auto_increment_tab.id = id; return test_auto_increment_tab; }
/// <summary> /// 用于向 test_auto_increment_tab EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet<T> 属性的 .Add 方法。 /// </summary> public void AddTotest_auto_increment_tab(test_auto_increment_tab test_auto_increment_tab) { base.AddObject("test_auto_increment_tab", test_auto_increment_tab); }