本文整理汇总了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"));
}
}
示例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");
}
示例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"));
}
示例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"));
}