• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# UnitOfWorkScope类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中UnitOfWorkScope的典型用法代码示例。如果您正苦于以下问题:C# UnitOfWorkScope类的具体用法?C# UnitOfWorkScope怎么用?C# UnitOfWorkScope使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



UnitOfWorkScope类属于命名空间,在下文中一共展示了UnitOfWorkScope类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()
        {
            var customer = new Customer
            {
                FirstName = "Jane",
                LastName = "Doe"
            };
            var session = NHTestUtil.OrdersDomainFactory.OpenSession();
            ITransaction transaction = session.BeginTransaction();
            session.Save(customer);
            transaction.Commit();
            session.Evict(customer); //Detching from owning session
            session.Dispose(); //Auto flush

            using (var scope = new UnitOfWorkScope())
            {
                var repository = new NHRepository<Customer,int>();
                repository.Attach(customer);
                customer.LastName = "Changed";
                scope.Commit(); //Should change since the customer was attached to repository.
            }

            using (var testData = new NHTestData(NHTestUtil.OrdersDomainFactory.OpenSession()))
            {
                Customer savedCustomer = null;
                testData.Batch(x => savedCustomer = x.GetCustomerById(customer.CustomerID));
                Assert.IsNotNull(savedCustomer);
                Assert.AreEqual(savedCustomer.LastName, "Changed");
            }
        }
开发者ID:jmptrader,项目名称:WebFrameworkMVC,代码行数:30,代码来源:NHRepositoryQueryTest.cs


示例3: Test_Updating_Money_Amount_Updates_Amount_In_Store_And_Returns_Updated_Figure

        public void Test_Updating_Money_Amount_Updates_Amount_In_Store_And_Returns_Updated_Figure()
        {
            var newAmount = (decimal) new Random().Next();
            using (var testData = new NHTestDataGenerator(Factory.OpenSession()))
            {
                testData.Batch(actions => actions.CreateMonthlySalesSummaryForSalesPerson(1));

                using (var scope = new UnitOfWorkScope())
                {
                    var repository = new NHRepository<MonthlySalesSummary>();
                    var report = (from summary in repository
                                  where summary.SalesPersonId == 1
                                  select summary).SingleOrDefault();
                    report.TotalSale.Amount = newAmount;
                    scope.Commit();
                }

                using (var scope = new UnitOfWorkScope())
                {
                    var repository = new NHRepository<MonthlySalesSummary>();
                    var report = (from summary in repository
                                  where summary.SalesPersonId == 1
                                  select summary).SingleOrDefault();

                    Assert.That(report.TotalSale.Amount, Is.EqualTo(newAmount));
                    scope.Commit();
                }
            }
        }
开发者ID:Chris-Kim,项目名称:ncommon,代码行数:29,代码来源:CompositeUserTypeBaseTests.cs


示例4: Test_Can_Query_MonthlySalesSummary_Based_On_Currency

        public void Test_Can_Query_MonthlySalesSummary_Based_On_Currency()
        {
            IList<MonthlySalesSummary> report;
            using (var testData = new NHTestDataGenerator(Factory.OpenSession()))
            using (var scope = new UnitOfWorkScope())
            {
                testData.Batch(actions => actions.CreateMonthlySalesSummaryWithAmount(
                    new Money{Amount = 100, Currency = "YEN"}
                    ));

                var repository = new NHRepository<MonthlySalesSummary>();
                report = (from summary in repository
                          where summary.TotalSale.Currency == "YEN"
                          select summary).ToList();

                scope.Commit();
            }

            Assert.That(report, Is.Not.Null);
            Assert.That(report.Count, Is.GreaterThan(0));

            report.ForEach(rep =>
            {
                Assert.That(rep.TotalSale, Is.Not.Null);
                Assert.That(rep.TotalSale.Amount, Is.GreaterThan(0));
                Assert.That(rep.TotalSale.Currency, Is.Not.Null);
                Assert.That(rep.TotalSale.Currency, Is.EqualTo("YEN"));
            });
        }
开发者ID:Chris-Kim,项目名称:ncommon,代码行数:29,代码来源:CompositeUserTypeBaseTests.cs


示例5: Test_Can_Get_MonthlySalesSummary_With_Money_Type

        public void Test_Can_Get_MonthlySalesSummary_With_Money_Type()
        {
            IList<MonthlySalesSummary> report;
            using (var testData = new NHTestDataGenerator(Factory.OpenSession()))
            using (var scope = new UnitOfWorkScope())
            {
                testData.Batch(action => action.CreateMonthlySalesSummaryForMonth(1));

                var repository = new NHRepository<MonthlySalesSummary>();
                report = (from summary in repository
                          where summary.Month == 1
                          select summary).ToList();

                scope.Commit();
            }

            Assert.That(report, Is.Not.Null);
            Assert.That(report.Count, Is.GreaterThan(0));

            report.ForEach(rep =>
                               {
                                   Assert.That(rep.Month == 1);
                                   Assert.That(rep.TotalSale, Is.Not.Null);
                                   Assert.That(rep.TotalSale.Amount, Is.GreaterThan(0));
                                   Assert.That(rep.TotalSale.Currency, Is.Not.Null);
                               });
        }
开发者ID:Chris-Kim,项目名称:ncommon,代码行数:27,代码来源:CompositeUserTypeBaseTests.cs


示例6: btnGenerate_Click

        protected void btnGenerate_Click(object sender, DirectEventArgs e)
        {
            using (var unitOfWork = new UnitOfWorkScope(true))
            {
                BusinessLogic.GenerateBillFacade.GenerateReceivable(dtGenerationDate.SelectedDate);
            }
            using (var unitOfWork = new UnitOfWorkScope(true))
            {

                LoanAccount.UpdateLoanAccountStatus(dtGenerationDate.SelectedDate);
            }
            using (var unitOfWork = new UnitOfWorkScope(true))
            {
                DemandLetter.UpdateDemandLetterStatus(dtGenerationDate.SelectedDate);
            }
            using (var unitOfWork = new UnitOfWorkScope(true))
            {
                Customer.UpdateCustomerStatus(dtGenerationDate.SelectedDate);
            }
            using (var unitOfWork = new UnitOfWorkScope(true))
            {

                FinancialProduct.UpdateStatus();

            }
        }
开发者ID:wainona,项目名称:PamaranLending,代码行数:26,代码来源:GenerateBill.aspx.cs


示例7: Can_eager_fetch_many

        public void Can_eager_fetch_many()
        {
            var testData = new EFTestData(Context);

            Customer customer = null;
            Customer savedCustomer = null;
            testData.Batch(x =>
            {
                customer = x.CreateCustomer();
                var order = x.CreateOrderForCustomer(customer);
                order.OrderItems.Add(x.CreateOrderItem(item => item.Order = order));
                order.OrderItems.Add(x.CreateOrderItem(item => item.Order = order));
                order.OrderItems.Add(x.CreateOrderItem(item => item.Order = order));
            });

            using (var scope = new UnitOfWorkScope())
            {
                savedCustomer = new EFRepository<Customer,int>()
                    .FetchMany(x => x.Orders)
                    .ThenFetchMany(x => x.OrderItems)
                    .ThenFetch(x => x.Product).Query
                    .Where(x => x.CustomerID == customer.CustomerID)
                    .SingleOrDefault();
                scope.Commit();
            }

            Assert.IsNotNull(savedCustomer);
            Assert.IsNotNull(savedCustomer.Orders);
            savedCustomer.Orders.ForEach(order =>
            {
                Assert.IsNotNull(order.OrderItems);
                order.OrderItems.ForEach(orderItem => Assert.IsNotNull(orderItem.Product));
            });
        }
开发者ID:jmptrader,项目名称:WebFrameworkMVC,代码行数:34,代码来源:EFRepositoryEagerFetchingTest.cs


示例8: ChangeToZero

 public bool ChangeToZero(int loanid)
 {
     using (var unitOfWork = new UnitOfWorkScope(true))
     {
         return ChangeInterestTypeFacade.SaveInterestType(loanid, InterestType.ZeroInterestTYpe, 0);
     }
 }
开发者ID:wainona,项目名称:PamaranLending,代码行数:7,代码来源:ListLoanRestructure.aspx.cs


示例9: GetCar

public static Entities.Car GetCar(int id)
{
    using (var uow = new UnitOfWorkScope<CarsContext>(UnitOfWorkScopePurpose.Reading))
    {
        return uow.DbContext.Cars.Single(c => c.CarId == id);
    }
}
开发者ID:harpagornis,项目名称:coding.abel.nu,代码行数:7,代码来源:SharedQueries.cs


示例10: TestInitialize

        public void TestInitialize()
        {
            _scope = new UnitOfWorkScope(new EFUnitOfWorkFactory(() => new DataContainer()));

            basicInfoDomainServiceObjects = new BasicInfoDomainServiceObjectsContainer(_scope);

            OrderConfigurator orderConfigurator = null;
            //new OrderConfigurator(new OrderStateFactory(new FuelReportDomainService(new FuelReportRepository(_scope),
            //    new VoyageDomainService( new VoyageRepository(_scope)),new InventoryOperationDomainService(new InventoryOperationRepository(_scope)),
            //    new InventoryOperationRepository(_scope),new InventoryOperationFactory()   ),new InvoiceDomainService() ));

            var client = new WebClientHelper(new HttpClient());
            _orderRepository = new OrderRepository(_scope, orderConfigurator, new EFRepository<OrderItem>(_scope));
            _orderRepository.GetAll();
            _tr = new TransactionScope();

            var hostAdapter = new ExternalHostAddressHelper();

            _target = new GoodFacadeService(
                new GoodDomainService(
                    new GoodAntiCorruptionAdapter(
                        new GoodAntiCorruptionServiceWrapper
                    (client, hostAdapter),
                    new GoodAntiCorruptionMapper()),
                    new EFRepository<Good>(_scope),
                    basicInfoDomainServiceObjects.CompanyDomainService, new EFRepository<GoodUnit>(_scope)),
                    new GoodToGoodDtoMapper(new CompanyGoodUnitToGoodUnitDtoMapper()));
        }
开发者ID:hatefi-arman,项目名称:Modules,代码行数:28,代码来源:GoodFacadeServiceTests.cs


示例11: can_commit_multiple_db_operations

        public void can_commit_multiple_db_operations()
        {
            var customer = new Customer { FirstName = "John", LastName = "Doe" };
            var salesPerson = new SalesPerson { FirstName = "Jane", LastName = "Doe", SalesQuota = 2000 };

            using (var scope = new UnitOfWorkScope())
            {
                new EFRepository<Customer>().Add(customer);
                new EFRepository<SalesPerson>().Add(salesPerson);
                scope.Commit();
            }

            using (var ordersTestData = new EFTestData(OrdersContextProvider()))
            using (var hrTestData = new EFTestData(HRContextProvider()))
            {
                Customer savedCustomer = null;
                SalesPerson savedSalesPerson = null;
                ordersTestData.Batch(action => savedCustomer = action.GetCustomerById(customer.CustomerID));
                hrTestData.Batch(action => savedSalesPerson = action.GetSalesPersonById(salesPerson.Id));

                Assert.That(savedCustomer, Is.Not.Null);
                Assert.That(savedSalesPerson, Is.Not.Null);
                Assert.That(savedCustomer.CustomerID, Is.EqualTo(customer.CustomerID));
                Assert.That(savedSalesPerson.Id, Is.EqualTo(salesPerson.Id));
            }
        }
开发者ID:jordanyaker,项目名称:ncommon,代码行数:26,代码来源:EFRepositoryTransactionTests.cs


示例12: ChangePassword

 public virtual void ChangePassword(Guid id, string oldPassword, string newPassword)
 {
     using (var scope = new UnitOfWorkScope())
     {
         _userAccountService.ChangePassword(id,oldPassword,newPassword);
         scope.Commit();
     }
 }
开发者ID:jmptrader,项目名称:WebFrameworkSPA,代码行数:8,代码来源:UserService.cs


示例13: CancelVerification

 public void CancelVerification(string key, out bool accountClosed)
 {
     using (var scope = new UnitOfWorkScope())
     {
         _userAccountService.CancelVerification(key,out accountClosed);
         scope.Commit();
     }
 }
开发者ID:jmptrader,项目名称:WebFrameworkSPA,代码行数:8,代码来源:UserService.cs


示例14: TestInitialize

        public void TestInitialize()
        {
            _scope = new UnitOfWorkScope(new EFUnitOfWorkFactory(() => new DataContainer()));

            _orderRepository = null;//new OrderRepository(_scope, new OrderConfigurator(new StateFactory(new )), new EFRepository<OrderItem>(_scope));
            _orderRepository.GetAll();

            _target = new OrderDomainService(_orderRepository);
        }
开发者ID:hatefi-arman,项目名称:Modules,代码行数:9,代码来源:OrderDomainServiceTest.cs


示例15: btnDeactivate_Click

 protected void btnDeactivate_Click(object sender, DirectEventArgs e)
 {
     FinancialProductForm form = this.CreateOrRetrieve<FinancialProductForm>();
     using (var unitOfWork = new UnitOfWorkScope(true))
     {
         ProductStatu status = ProductStatu.ChangeStatus(form.FinancialProductId, ProductStatusType.InactiveType, DateTime.Now);
         EnableValidActivity(status);
     }
 }
开发者ID:wainona,项目名称:PamaranLending,代码行数:9,代码来源:ViewOrEditFinancialProduct.aspx.cs


示例16: btnSave_Click

        protected void btnSave_Click(object sender, DirectEventArgs e)
        {
            var today = DateTime.Now;

            using (var unitOfWork = new UnitOfWorkScope())
            {
                LoanRestructureForm form = this.CreateOrRetrieve<LoanRestructureForm>();
                form.SaveChangeIcmAmortizationSchedule(today);
            }
        }
开发者ID:wainona,项目名称:PamaranLending,代码行数:10,代码来源:AmortizationScheduleChangeInterest.aspx.cs


示例17: btnSave_Click

 protected void btnSave_Click(object sender, DirectEventArgs e)
 {
     using (var unitOfWork = new UnitOfWorkScope(true))
     {
         int id = int.Parse(this.RecordID.Text);
         AssetType asset = ObjectContext.AssetTypes.SingleOrDefault(entity => entity.Id == id);
         asset.Name = this.txtName.Text;
         asset.IsAppraisableIndicator = this.radTrue.Checked;
     }
 }
开发者ID:wainona,项目名称:PamaranLending,代码行数:10,代码来源:SimpleAddEditTemplate.aspx.cs


示例18: ChangeToFixed

 public bool ChangeToFixed(int loanid)
 {
     decimal amount = 0;
     if (string.IsNullOrWhiteSpace(txtInterest.Text) == false)
         amount = decimal.Parse(txtInterest.Text);
     using (var unitOfWork = new UnitOfWorkScope(true))
     {
         return ChangeInterestTypeFacade.SaveInterestType(loanid, InterestType.FixedInterestTYpe, amount);
     }
 }
开发者ID:wainona,项目名称:PamaranLending,代码行数:10,代码来源:ListLoanRestructure.aspx.cs


示例19: ChangePasswordFromResetKey

 public bool ChangePasswordFromResetKey(string key, string newPassword, out NhUserAccount account)
 {
     bool success;
     using (var scope = new UnitOfWorkScope())
     {
         success=_userAccountService.ChangePasswordFromResetKey(key,newPassword,out account);
         scope.Commit();
     }
     return success;
 }
开发者ID:jmptrader,项目名称:WebFrameworkSPA,代码行数:10,代码来源:UserService.cs


示例20: AddUsersToRoles

        public virtual void AddUsersToRoles(List<Guid> userId, List<string> roleName)
        {
            if (userId == null || userId.Count == 0 || roleName == null || roleName.Count == 0)
                return;
            StringBuilder message=new StringBuilder();
            var users = _userRepository.Query.Where(x => userId.Contains(x.ID)).ToList();
            var roles = _roleRepository.Query.Where(x => roleName.Contains(x.Name)).ToList();
            foreach (var userEntity in users)
            {
                if (userEntity.Roles != null && userEntity.Roles.Any())
                {
                    var newRoles = roles.Except(userEntity.Roles);

                    foreach (var role in newRoles)
                        userEntity.Roles.Add(role);
                    if(newRoles!=null && newRoles.Count()>0)
                        message.AppendFormat("User {0} is added to role(s) {1}.",userEntity.Username,string.Join(",", newRoles.Select(x => x.Name)));
                }
                else
                {
                    foreach (var role in roles)
                        userEntity.Roles.Add(role);
                    if(roles!=null && roles.Count()>0)
                        message.AppendFormat("User {0} is added to role(s) {1}.",userEntity.Username,string.Join(",", roles.Select(x => x.Name)));
                }
                using (var scope = new UnitOfWorkScope())
                {
                    _userRepository.Update(userEntity);
                    scope.Commit();
                }
            }
            foreach (var uid in userId)
            {
                if (!users.Any(u => u.ID == uid))
                {
                    var user = _userRepository.Query.Where(x => x.ID == uid).SingleOrDefault();
                    if (user != null)
                    {
                        user.Roles = roles;
                        using (var scope = new UnitOfWorkScope())
                        {
                            _userRepository.Update(user);
                            scope.Commit();
                        }
                        if(roles!=null && roles.Count()>0)
                            message.AppendFormat("User {0} is added to role(s) {1}.",user.Username,string.Join(",", roles.Select(x => x.Name)));
                    }
                }
            }
            if (message.Length > 0)
            {
                ActivityLog item = new ActivityLog(ActivityType.AddUserToRole.ToString(), message.ToString());
                _activityLogService.Add(item);
            }
        }
开发者ID:jmptrader,项目名称:WebFrameworkMVC,代码行数:55,代码来源:RoleService.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# UnitPoint类代码示例发布时间:2022-05-24
下一篇:
C# UnitOfWork类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap