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


C# Test.SubmitChanges方法代码示例

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


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

示例1: TestIdeneity

        /// <summary>
        /// 测试 Identity 的处理.
        /// </summary>
        private static void TestIdeneity()
        {

            Console.WriteLine("===== 测试父子关系表的 Identity 的处理.");

            using (Test context = new Test(connString))
            {
                test_Identity_tab testMainData = new test_Identity_tab()
                {
                    value = "测试主"
                };

                test_Identity_tab_Sub testSubData = new test_Identity_tab_Sub()
                {
                    Value = "测试子"
                };

                testSubData.test_Identity_tab = testMainData;


                // 插入.
                context.test_Identity_tab.InsertOnSubmit(testMainData);
                context.test_Identity_tab_Sub.InsertOnSubmit(testSubData);

                Console.WriteLine("Before SubmitChanges testMainData.id = {0}", testMainData.id);
                Console.WriteLine("Before SubmitChanges testSubData.id = {0}", testSubData.Id);

                context.SubmitChanges();

                Console.WriteLine("After SubmitChanges testMainData.id = {0}", testMainData.id);
                Console.WriteLine("After SubmitChanges testSubData.id = {0}", testSubData.Id);
            }

        }
开发者ID:mahuidong,项目名称:my-csharp-sample,代码行数:37,代码来源:Program.cs

示例2: BaseTest

        /// <summary>
        /// Linq2SQL 基本功能测试
        /// 
        /// 基本的 查询 / 插入 / 更新 / 删除 处理.
        /// 
        /// </summary>
        private static void BaseTest()
        {
            Test context = new Test(connString);






            // 单表查询
            var query =
                from testMain in context.TestMain
                select testMain;
            foreach (TestMain main in query)
            {
                Console.WriteLine("Main[{0}, {1}]", main.Id, main.Value);
            }

            // 关联查询
            var query2 =
                from testSub in context.TestSub
                where testSub.TestMain.Value == "ONE"
                select testSub;
            foreach (TestSub sub in query2)
            {
                Console.WriteLine("Sub[{0}, {1}]", sub.Id, sub.Value);
            }

            // 插入.
            TestMain main3 = new TestMain();
            main3.Id = 3;
            main3.Value = "Three";
            context.TestMain.InsertOnSubmit(main3);
            context.SubmitChanges();

            Console.WriteLine("INSERT FINISH! --- Please Press Enter Ket");
            Console.ReadLine();

            // 更新.
            var newTestMain =
                (from testMain in context.TestMain
                 where testMain.Id == 3
                 select testMain).First();
            newTestMain.Value = "Three3";
            context.SubmitChanges();

            Console.WriteLine("UPDATE FINISH!  --- Please Press Enter Ket");
            Console.ReadLine();


            // 单表查询 TOP 2
            var queryTop2 =
                (from testMain in context.TestMain
                 orderby testMain.Id descending
                 select testMain).Take(2);

            foreach (TestMain main in queryTop2)
            {
                Console.WriteLine("Main[{0}, {1}]", main.Id, main.Value);
            }

            // 删除.
            context.TestMain.DeleteOnSubmit(newTestMain);
            context.SubmitChanges();

            Console.WriteLine("DELETE FINISH! --- Please Press Enter Ket");
            Console.ReadLine();

        }
开发者ID:mahuidong,项目名称:my-csharp-sample,代码行数:75,代码来源:Program.cs

示例3: TransactionTest

        /// <summary>
        /// 事务处理的测试.
        /// 
        /// 隐式创建事务
        /// 
        /// </summary>
        private static void TransactionTest()
        {
            // 在我们没有显式的开启事务时,
            // DataContext.SubmitChanges在提交时会隐式创建事务

            Test context = new Test(connString);

            try
            {

                // 插入.
                TestMain main3 = new TestMain();
                main3.Id = 3;
                main3.Value = "Three";
                context.TestMain.InsertOnSubmit(main3);


                TestMain main3x = new TestMain();
                main3x.Id = 3;
                main3x.Value = "Three Err";
                context.TestMain.InsertOnSubmit(main3x);


                context.SubmitChanges();

            }
            catch (Exception err)
            {
                Console.WriteLine(err.ToString());              
            }


            var query =
               from testMain in context.TestMain
               where testMain.Id == 3
               select testMain;

            Console.WriteLine("TestMain 表中, id=3 的记录有{0}条 ", query.Count());


        }
开发者ID:mahuidong,项目名称:my-csharp-sample,代码行数:47,代码来源:Program.cs


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