本文整理汇总了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;
}
示例2: Start
public void Start()
{
if (!UnitOfWork.IsStarted ||
transactionMode != TransactionMode.Requires ||
!UnitOfWork.Current.IsInActiveTransaction)
{
unitOfWork = UnitOfWork.Start();
rhinoTransaction = unitOfWork.BeginTransaction();
}
}
示例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>();
}
示例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();
}
示例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();
}
示例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;
}
示例7: CreateRole
private static void CreateRole(IRoleService roleService, IUnitOfWork unitOfWork, string roleName)
{
unitOfWork.BeginTransaction();
roleService.CreateRole(roleName);
unitOfWork.Commit();
}
示例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;
}
示例9: BeginTransaction
public void BeginTransaction()
{
_uow = ServiceLocator.Current.GetInstance<IUnitOfWork>();
_uow.BeginTransaction();
}
示例10: OpenSession
private void OpenSession(object sender, EventArgs e)
{
_session = Locator.GetComponet<IUnitOfWork>();
_session.BeginTransaction();
}
示例11: BeginTransaction
public void BeginTransaction()
{
_unitOfWork = ObjectFactory.GetInstance<IUnitOfWork>();
_unitOfWork.BeginTransaction();
}