Skip to content

Best practice for multiple data contexts for accessing different databases with different schemas #4102

Closed Answered by viceroypenguin
BenjaBobs asked this question in Q&A
Discussion options

You must be logged in to vote

Presumably you already have a class FruitDbContext : DataConnection and a class AnimalDbContext : DataConnection (which would also give you access to the tables on those connections); so you could just write the extensions:

public static class FruitConnectionExtensions
{
  public static async Task EatFruits(this FruitDbContext fruitConnection)
  {
    // Do some fruit specific stuff
  }
}

public static class AnimalConnectionExtensions
{
  public static async Task Bark(this AnimalDbContext animalContext, int dogId)
  {
    // Log that the dog barked
  }
}

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@BenjaBobs
Comment options

@viceroypenguin
Comment options

Answer selected by BenjaBobs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants