Xaisoft
Xaisoft

Reputation: 46651

Using two Object Contexts?

I created two edmx files and have to contexts.

Is there a problem with doing something like:

public DataManager
{
  protected ObjectContext _context;

  public DataManager(ObjectContext context)
  {
     _context = context;
  }
}

or is it better to have an overloaded construtor:

public DataManager
{
  protected db1entities _context;
  protected db2entities _context2;

  public DataManager(db2entities context)
  {
     _context = context;
  }

  public DataManager(db2entities context)
  {
     _context2 = context;
  }
}

I noticed if I do it the first way, then the context does not know about my entities, where as it does if I explicitly specify the context

Upvotes: 0

Views: 57

Answers (1)

DCNYAM
DCNYAM

Reputation: 12126

I'm not entirely sure what you are trying to accomplish, but you could also do this using generics (http://msdn.microsoft.com/en-us/library/512aeb7t(v=vs.110).aspx). Something like...

public class DataManager<T> where T:ObjectContext
{
  protected T _context;

  public DataManager(T context)
  {
     _context = context;
  }
}

Then ...

DataManager<db1Entities> DataManager1;
DataManager<db2Entities> DataManager2;

Upvotes: 2

Related Questions