Question

Lets say I have a class Foods

public class FoodsContext : DbContext, IUnitOfWork
{
   public DbSet<Consumer> Consumers {get; set;}
}

and there is class Fruits

public class FruitsContext: FoodsContext
{
   public DbSet<Price> Prices {get; set;}
}

then in my repository Lets say I have

public class SampleRepository
{
   private readonly FruitsContext _dbFruits = new FruitsContext();

   public void foo()
   {
      _dbFruits.Prices.doanything;
      //how can i use Consumers table that has been set in Foods class
   }
}

In my repository class I want to access values from Consumers table, without creating an instance of Food class. How can I do that?

I had seen this in some project but I don't quite remember it now. Can someone suggest something?

Was it helpful?

Solution 2

You could also do

public void foo()
{
  _dbFruits.Prices.doanything;
  //how can i use Consumers table that has been set in Foods class
  _dbFruits.Set<Consumer>.doanything;
}

OTHER TIPS

It looks like plain inheritance to me:

public void foo()
{
  _dbFruits.Prices.doanything;
  //how can i use Consumers table that has been set in Foods class
  _dbFruits.Consumers.doanything;  // this should work
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top