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


C# EFRepository.Attach方法代码示例

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


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

示例1: Can_attach_modified_entity

        public void Can_attach_modified_entity()
        {
            var customer = new Customer
            {
                FirstName = "John",
                LastName = "Doe"
            };

            var context = (OrderEntities) OrdersContextProvider();
            context.AddToCustomers(customer);
            #if EF_1_0
            context.SaveChanges(true);
            #else
            context.SaveChanges(SaveOptions.AcceptAllChangesAfterSave);
            #endif
            context.Detach(customer);
            context.Dispose();

            using (var scope = new UnitOfWorkScope())
            {
                customer.LastName = "Changed";
                var repository = new EFRepository<Customer>();
                repository.Attach(customer);
                scope.Commit();
            }

            using (var testData = new EFTestData(OrdersContextProvider()))
            {
                Customer savedCustomer = null;
                testData.Batch(x => savedCustomer = x.GetCustomerById(customer.CustomerID));
                Assert.That(savedCustomer, Is.Not.Null);
                Assert.That(savedCustomer.LastName, Is.EqualTo("Changed"));
            }
        }
开发者ID:jordanyaker,项目名称:ncommon,代码行数:34,代码来源:EFRepositoryQueryTests.cs

示例2: Can_attach

        public void Can_attach()
        {
            Customer customer = null;
            var testData = new EFTestData(Context);
            testData.Batch(x => customer = x.CreateCustomer());
            testData.Context.Detach(customer);
            Context.Dispose();

            using (var scope = new UnitOfWorkScope())
            {
                var repository = new EFRepository<Customer,int>();
                repository.Attach(customer);
                customer.FirstName = "Changed";
                scope.Commit();
            }

            testData = new EFTestData(Context);
            customer = testData.Get<Customer>(x => x.CustomerID == customer.CustomerID);
            Assert.AreEqual(customer.FirstName, "Changed");
        }
开发者ID:jmptrader,项目名称:WebFrameworkMVC,代码行数:20,代码来源:EFRepositoryQueryTests.cs

示例3: Can_attach_modified_entity

        public void Can_attach_modified_entity()
        {
            Customer customer = null;
            var testData = new EFTestData(Context);
            testData.Batch(x => customer = x.CreateCustomer());
            Context.Detach(customer);
            Context.Dispose();

            using (var scope = new UnitOfWorkScope())
            {
                customer.LastName = "Changed";
                var repository = new EFRepository<Customer>();
                repository.Attach(customer);
                scope.Commit();
            }

            Context = new PocoContext(ConnectionString);
            testData = new EFTestData(Context);
            customer = testData.Get<Customer>(x => x.CustomerID == customer.CustomerID);
            Assert.That(customer.LastName, Is.EqualTo("Changed"));
        }
开发者ID:jordanyaker,项目名称:ncommon,代码行数:21,代码来源:EFRepositoryQueryTests.cs

示例4: Can_attach

        public void Can_attach()
        {
            Customer customer = null;
            var testData = new EFTestData(Context);
            testData.Batch(x => customer = x.CreateCustomer());
            Context.Detach(customer);
            Context.Dispose();

            using (var scope = new UnitOfWorkScope())
            {
                var repository = new EFRepository<Customer>();
                repository.Attach(customer);
                customer.FirstName = "Changed";
                scope.Commit();
            }

            Context = new CodeOnlyContext("SandboxCodeOnly").Context;
            testData = new EFTestData(Context);
            customer = testData.Get<Customer>(x => x.CustomerID == customer.CustomerID);
            Assert.That(customer.FirstName, Is.EqualTo("Changed"));
        }
开发者ID:jordanyaker,项目名称:ncommon,代码行数:21,代码来源:EFRepositoryQueryTests.cs


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