开发者

EF Repository library for multiple db contexts

Anyone suggest me how to build an EF repository pattern that supports multiple contexts (more than one Db context each one belongs to a separate DB.).

R开发者_运维知识库egards, Hareen.


Use a dependency injection framework to inject the Contexts for your repositories.

public class FooRepository
{
  FirstContext _fc;
  SecondContext _sc

  public FooRepository(FirstContext fc, SecondContext sc)
  {
     _fc = fc;
     _sc = sc;
  }
}

public class BarRepository
{
  FirstContext _fc;
  SecondContext _sc
  ThirdContext _tc

  public BarRepository(FirstContext fc, SecondContext sc, ThirdContext tc)
  {
     _fc = fc;
     _sc = sc;
     _tc = tc;
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜