本文整理汇总了C#中UnitOfWorkScope类的典型用法代码示例。如果您正苦于以下问题:C# UnitOfWorkScope类的具体用法?C# UnitOfWorkScope怎么用?C# UnitOfWorkScope使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnitOfWorkScope类属于命名空间,在下文中一共展示了UnitOfWorkScope类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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"));
}
}
示例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");
}
}
示例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();
}
}
}
示例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"));
});
}
示例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);
});
}
示例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();
}
}
示例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));
});
}
示例8: ChangeToZero
public bool ChangeToZero(int loanid)
{
using (var unitOfWork = new UnitOfWorkScope(true))
{
return ChangeInterestTypeFacade.SaveInterestType(loanid, InterestType.ZeroInterestTYpe, 0);
}
}
示例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);
}
}
示例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()));
}
示例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));
}
}
示例12: ChangePassword
public virtual void ChangePassword(Guid id, string oldPassword, string newPassword)
{
using (var scope = new UnitOfWorkScope())
{
_userAccountService.ChangePassword(id,oldPassword,newPassword);
scope.Commit();
}
}
示例13: CancelVerification
public void CancelVerification(string key, out bool accountClosed)
{
using (var scope = new UnitOfWorkScope())
{
_userAccountService.CancelVerification(key,out accountClosed);
scope.Commit();
}
}
示例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);
}
示例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);
}
}