0

I'm using “ADO.NET Unit Testable Repository Generator" (described here) to generate the entity classes. This T4 template automatically generates the following classes, apart from the classes for the database objects:

  1. <MyEntities>.cs - The functional concrete object context
  2. <MyEntities>BaseRepositoryTest.cs
  3. <MyEntities>Mock.cs - The concrete mock context object that implements the context's interface.
  4. <MyEntities>Mock.ObjectSet.cs
  5. <MyModelRepository>.Context.cs
  6. <MyEntities>PartialRespository.cs
  7. I<MyEntities>.cs - The interface for the specialised object context.

I am not completely sure what some of these classes are for.

I am using a manager class that performs all database access/update operations.

// Contains all Methods that access the database 
public class DataManager
{
    private IMyEntities _context;

    public DataManager()
        : this(new MyEntities())
    {
    }

    public bool AddOrder(Order order)
    {
      _context.Orders.AddObject(order);
      _context.SaveChanges();
    }
  ...
  }

i want to check for concurrency exceptions when I call _context.SaveChanges(). Ideally, I would like to call _context.Refresh() in case of a concurrency issue. However, the autogenerated ObjectContext class IMyEntities does have a method like ObjectContext.Refresh()

What am I doing wrong? How can I call Refresh()?

escist
  • 763
  • 4
  • 13
  • 35

1 Answers1

0

AFAIK this can't be done since IMyEntities does not inherit ObjectContext. But MyEntities does.

When I change

private IMyEntities _context;

to

private MyEntities _context;

I can call ObjectContext.Refresh() using _context.Refresh().

escist
  • 763
  • 4
  • 13
  • 35