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


C# IUnitOfWork.BeginTransaction方法代码示例

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


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

示例1: BeforeCall

        public object BeforeCall(RouteContext ctx)
        {
            _uow = DependencyContainer.Current.Resolve<IUnitOfWork>();

            if (ctx.Method.HttpMethod != HttpMethod.Get)
            {
                _uow.BeginTransaction();
            }
            return null;
        }
开发者ID:mehmetatas,项目名称:monospad,代码行数:10,代码来源:UnitOfWorkInterceptor.cs

示例2: Start

 public void Start()
 {
     if (!UnitOfWork.IsStarted ||
         transactionMode != TransactionMode.Requires ||
         !UnitOfWork.Current.IsInActiveTransaction)
     {
         unitOfWork = UnitOfWork.Start();
         rhinoTransaction = unitOfWork.BeginTransaction();
     }
 }
开发者ID:JackWangCUMT,项目名称:rhino-tools,代码行数:10,代码来源:RhinoTransactionResourceAdapter.cs

示例3: UnitOfWorkScopeTransaction

 /// <summary>
 /// Overloaded Constructor.
 /// Creates a new instance of the <see cref="UnitOfWorkScopeTransaction"/> that takes in a 
 /// <see cref="IUnitOfWorkFactory"/> instance that is responsible for creating instances of <see cref="IUnitOfWork"/> and
 /// a <see cref="IDbConnection"/> that is used by the instance to connect to the data store.
 /// </summary>
 /// <param name="unitOfWorkFactory">The <see cref="IUnitOfWorkFactory"/> implementation that is responsible
 /// for creating instances of <see cref="IUnitOfWork"/> instances.</param>
 /// <param name="isolationLevel">One of the values of <see cref="IsolationLevel"/> that specifies the transaction
 /// isolation level of the <see cref="UnitOfWorkScopeTransaction"/> instance.</param>
 public UnitOfWorkScopeTransaction(IUnitOfWorkFactory unitOfWorkFactory, IsolationLevel isolationLevel)
 {
     Guard.Against<ArgumentNullException>(unitOfWorkFactory == null,
                                          "A valid non-null instance that implements the IUnitOfWorkFactory is required.");
     _transactionID = new Guid();
     _transactionRolledback = false;
     _disposed = false;
     _unitOfWork = unitOfWorkFactory.Create();
     _runningTransaction = _unitOfWork.BeginTransaction(isolationLevel);
     _isolationLevel = isolationLevel;
     _attachedScopes = new Stack<UnitOfWorkScope>();
 }
开发者ID:tmchan,项目名称:ncommon,代码行数:22,代码来源:UnitOfWorkScopeTransaction.cs

示例4: RemoveUsersFromRoles

        private static void RemoveUsersFromRoles(IRepository repository, IUnitOfWork unitOfWork, string[] userNames, string[] roleNames)
        {
            unitOfWork.BeginTransaction();

            var distinctRoleNames = roleNames.Distinct().ToList();
            var futureQueries = new List<IEnumerable<Models.Role>>();

            foreach (var userName in userNames.Distinct())
            {
                var futureQuery = repository
                    .AsQueryable<Models.UserRole>(userRole => userRole.User.UserName == userName
                        && distinctRoleNames.Contains(userRole.Role.Name))
                    .Select(userRole => new Models.Role
                        {
                            Id = userRole.Id,
                            Version = userRole.Version
                        })
                    .ToFuture();
                
                futureQueries.Add(futureQuery);
            }

            futureQueries.ForEach(futureQuery => 
                futureQuery.ToList().ForEach(role => 
                    repository.Delete<Models.UserRole>(role.Id, role.Version)));

            unitOfWork.Commit();
        }
开发者ID:Steinerd,项目名称:BetterCMS,代码行数:28,代码来源:CmsRoleProvider.cs

示例5: AddUsersToRoles

        private static void AddUsersToRoles(IRepository repository, IUnitOfWork unitOfWork, string[] userNames, string[] roleNames)
        {
            unitOfWork.BeginTransaction();

            // Get roles future query
            var distinctRoleNames = roleNames.Distinct().ToArray();
            var roleIdsQuery = repository
                .AsQueryable<Models.Role>(role => distinctRoleNames.Contains(role.Name))
                .Select(role => new
                                    {
                                        Id = role.Id,
                                        Name = role.Name
                                    })
                .ToFuture();

            // Get users future query
            var distinctUserNames = userNames.Distinct().ToArray();
            var userIdsQuery = repository
                .AsQueryable<Models.User>(user => distinctUserNames.Contains(user.UserName))
                .Select(user => new
                                    {
                                        Id = user.Id,
                                        Name = user.UserName
                                    })
                .ToFuture();

            // Get already assigned roles
            var alreadyAssigned = repository
                .AsQueryable<Models.UserRole>(userRole => distinctUserNames.Contains(userRole.User.UserName))
                .Select(userRole => new
                                        {
                                            UserId = userRole.User.Id,
                                            RoleId = userRole.Role.Id
                                        })
                .ToFuture()
                .ToList();

            // Validate roles
            var roles = roleIdsQuery.ToList();
            roleNames
                .Where(roleName => roles.All(role => roleName != role.Name))
                .ForEach(roleName =>
                    { throw new ProviderException(string.Format("Role {0} does not exist.", roleName)); });

            // Validate users
            var users = userIdsQuery.ToList();
            userNames
                .Where(userName => users.All(user => userName != user.Name))
                .ForEach(userName =>
                    { throw new ProviderException(string.Format("User {0} does not exist.", userName)); });

            // Add users to roles
            roles
                .ForEach(role => users
                    .ForEach(user =>
                        {
                            if (!alreadyAssigned.Any(a => a.UserId == user.Id && a.RoleId == role.Id))
                            {
                                var userRole = new Models.UserRole
                                                   {
                                                       User = repository.AsProxy<Models.User>(user.Id),
                                                       Role = repository.AsProxy<Models.Role>(role.Id), 
                                                   };
                                repository.Save(userRole);
                            }
                        }));

            unitOfWork.Commit();
        }
开发者ID:Steinerd,项目名称:BetterCMS,代码行数:69,代码来源:CmsRoleProvider.cs

示例6: DeleteRole

        private static bool DeleteRole(IRoleService roleService, IUnitOfWork unitOfWork, string roleName, bool throwOnPopulatedRole)
        {
            unitOfWork.BeginTransaction();
            var role = roleService.DeleteRole(roleName, throwOnPopulatedRole);
            unitOfWork.Commit();

            Events.UserEvents.Instance.OnRoleDeleted(role);

            return true;
        }
开发者ID:Steinerd,项目名称:BetterCMS,代码行数:10,代码来源:CmsRoleProvider.cs

示例7: CreateRole

 private static void CreateRole(IRoleService roleService, IUnitOfWork unitOfWork, string roleName)
 {
     unitOfWork.BeginTransaction();
     roleService.CreateRole(roleName);
     unitOfWork.Commit();
 }
开发者ID:Steinerd,项目名称:BetterCMS,代码行数:6,代码来源:CmsRoleProvider.cs

示例8: ChangePassword

        private static bool ChangePassword(IAuthenticationService authenticationService, IUnitOfWork unitOfWork, string username, string oldPassword, string newPassword)
        {
            unitOfWork.BeginTransaction();
            var success = authenticationService.ChangePassword(username, oldPassword, newPassword);
            unitOfWork.Commit();

            return success;
        }
开发者ID:navid60,项目名称:BetterCMS,代码行数:8,代码来源:CmsMembershipProvider.cs

示例9: BeginTransaction

 public void BeginTransaction()
 {
     _uow = ServiceLocator.Current.GetInstance<IUnitOfWork>();
     _uow.BeginTransaction();
 }
开发者ID:edupinheiro,项目名称:CursoMVCAbril,代码行数:5,代码来源:AppServiceBase.cs

示例10: OpenSession

 private void OpenSession(object sender, EventArgs e)
 {
     _session = Locator.GetComponet<IUnitOfWork>();
     _session.BeginTransaction();
 }
开发者ID:ViniciusConsultor,项目名称:elias,代码行数:5,代码来源:SessionModule.cs

示例11: BeginTransaction

 public void BeginTransaction()
 {
     _unitOfWork = ObjectFactory.GetInstance<IUnitOfWork>();
     _unitOfWork.BeginTransaction();
 }
开发者ID:AlanBessa,项目名称:ForMeeting,代码行数:5,代码来源:BaseApp.cs


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