Exemplo n.º 1
0

        
Exemplo n.º 2
0
 public List<test_sub> GetTestSub(test_main testMain)
 {
     using (TestEntities context = new TestEntities())
     {
         // 返回 子数据列表.
         return context.test_sub.Where(p => p.main_id == testMain.id).ToList();
     }
 }
Exemplo n.º 3
0

        
Exemplo n.º 4
0
 public List<test_main> GetTestMain()
 {
     using (TestEntities context = new TestEntities())
     {
         // 返回 主数据列表.
         return context.test_main.ToList();
     }
 }
Exemplo n.º 5
0
        public bool TestInsertData(int main_id, string main_val, int sub_id, string sub_value)
        {
            // 请注意:
            // 由于是使用 WCF 来进行事务的管理.

            try
            {
                using (TestEntities context = new TestEntities())
                {
                    TEST_MAIN mainData = new TEST_MAIN()
                    {
                        ID    = main_id,
                        VALUE = main_val
                    };


                    TEST_SUB subData = new TEST_SUB()
                    {
                        ID      = sub_id,
                        MAIN_ID = main_id,
                        VALUE   = sub_value
                    };


                    context.AddToTEST_MAIN(mainData);

                    context.AddToTEST_SUB(subData);


                    context.SaveChanges();
                }



                return(true);
            }
            catch (Exception ex)
            {
                // 由于是使用 WCF 来管理事务.
                // 因此,发生异常了, 就必须抛出异常
                // 不能自己 Catch 住了, 然后简单返回 false.

                // 如果自己 Catch 住了,简单返回 false 的话, WCF 认为你的程序执行正常,就你做的修改提交了,而不是回滚掉。
                throw new FaultException(ex.ToString(), new FaultCode(ex.Message));
            }
        }
Exemplo n.º 6
0
        public bool TestInsertData(int main_id, string main_val, int sub_id, string sub_value)
        {
            // 请注意:
            // 由于是使用 WCF 来进行事务的管理.

            try
            {
                using (TestEntities context = new TestEntities())
                {
                    test_main mainData = new test_main()
                    {
                        id    = main_id,
                        value = main_val
                    };


                    test_sub subData = new test_sub()
                    {
                        id      = sub_id,
                        main_id = main_id,
                        value   = sub_value
                    };


                    context.AddTotest_main(mainData);

                    context.AddTotest_sub(subData);


                    context.SaveChanges();
                }



                return(true);
            }
            catch (Exception ex)
            {
                // 由于是使用 WCF 来管理事务.
                // 因此,发生异常了, 就必须抛出异常
                // 不能自己 Catch 住了, 然后简单返回 false.

                // 如果自己 Catch 住了,简单返回 false 的话, WCF 认为你的程序执行正常,就你做的修改提交了,而不是回滚掉。
                throw new FaultException(ex.ToString(), new FaultCode(ex.Message));
            }
        }
Exemplo n.º 7
0
        public bool TestDeleteData(int main_id)
        {
            try
            {
                using (TestEntities context = new TestEntities())
                {
                    var querySub =
                        from data in context.TEST_SUB
                        where data.MAIN_ID == main_id
                        select data;

                    foreach (TEST_SUB subData in querySub)
                    {
                        context.TEST_SUB.DeleteObject(subData);
                    }

                    var queryMain =
                        from data in context.TEST_MAIN
                        where data.ID == main_id
                        select data;

                    foreach (TEST_MAIN mainData in queryMain)
                    {
                        context.TEST_MAIN.DeleteObject(mainData);
                    }

                    context.SaveChanges();
                }

                return true;
            }
            catch (Exception ex)
            {
                // 由于是使用 WCF 来管理事务.
                // 因此,发生异常了, 就必须抛出异常
                // 不能自己 Catch 住了, 然后简单返回 false.

                // 如果自己 Catch 住了,简单返回 false 的话, WCF 认为你的程序执行正常,就你做的修改提交了,而不是回滚掉。
                throw new FaultException(ex.ToString(), new FaultCode(ex.Message));
            }
        }
Exemplo n.º 8
0
        public bool TestDeleteData(int main_id)
        {
            try
            {
                using (TestEntities context = new TestEntities())
                {
                    var querySub =
                        from data in context.TEST_SUB
                        where data.MAIN_ID == main_id
                        select data;

                    foreach (TEST_SUB subData in querySub)
                    {
                        context.TEST_SUB.DeleteObject(subData);
                    }

                    var queryMain =
                        from data in context.TEST_MAIN
                        where data.ID == main_id
                        select data;

                    foreach (TEST_MAIN mainData in queryMain)
                    {
                        context.TEST_MAIN.DeleteObject(mainData);
                    }

                    context.SaveChanges();
                }

                return(true);
            }
            catch (Exception ex)
            {
                // 由于是使用 WCF 来管理事务.
                // 因此,发生异常了, 就必须抛出异常
                // 不能自己 Catch 住了, 然后简单返回 false.

                // 如果自己 Catch 住了,简单返回 false 的话, WCF 认为你的程序执行正常,就你做的修改提交了,而不是回滚掉。
                throw new FaultException(ex.ToString(), new FaultCode(ex.Message));
            }
        }
Exemplo n.º 9
0
        public bool TestInsertSub(int id, int main_id, string val)
        {
            // 请注意:
            // 由于是使用 WCF 来进行事务的管理.

            try
            {
                using (TestEntities context = new TestEntities())
                {
                    TEST_SUB subData = new TEST_SUB()
                    {
                        ID = id,
                        MAIN_ID = main_id,
                        VALUE = val
                    };

                    context.AddToTEST_SUB(subData);

                    context.SaveChanges();
                }

                return true;
            }
            catch (Exception ex)
            {
                // 由于是使用 WCF 来管理事务.
                // 因此,发生异常了, 就必须抛出异常
                // 不能自己 Catch 住了, 然后简单返回 false.

                // 如果自己 Catch 住了,简单返回 false 的话, WCF 认为你的程序执行正常,就你做的修改提交了,而不是回滚掉。
                throw new FaultException(ex.ToString(), new FaultCode(ex.Message));
            }
        }
Exemplo n.º 10
0
        public bool TestInsertMain(int id, string val)
        {
            // 请注意:
            // 由于是使用 WCF 来进行事务的管理.

            try
            {

                using (TestEntities context = new TestEntities())
                {
                    test_main mainData = new test_main()
                    {
                        id = id,
                        value = val
                    };

                    context.AddTotest_main(mainData);

                    context.SaveChanges();
                }

                return true;
            }
            catch (Exception ex)
            {
                // 由于是使用 WCF 来管理事务.
                // 因此,发生异常了, 就必须抛出异常
                // 不能自己 Catch 住了, 然后简单返回 false.

                // 如果自己 Catch 住了,简单返回 false 的话, WCF 认为你的程序执行正常,就你做的修改提交了,而不是回滚掉。
                throw new FaultException(ex.ToString(), new FaultCode(ex.Message));
            }
        }