0

クラスFoodsがあるとしましょう

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

クラスFruitsがあります

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

次に、私のリポジトリにあるとしましょう

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
   }
}

私のリポジトリ クラスでは、 Foodクラスのインスタンスを作成せずに、 Consumersテーブルの値にアクセスしたいと考えています。どうやってやるの?

これは何かのプロジェクトで見たことがありますが、今はよく覚えていません。誰かが何かを提案できますか?

4

2 に答える 2

2

私には単純な継承のように見えます:

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
}
于 2013-07-26T12:35:30.547 に答える
0

あなたもできる

public void foo()
{
  _dbFruits.Prices.doanything;
  //how can i use Consumers table that has been set in Foods class
  _dbFruits.Set<Consumer>.doanything;
}
于 2013-07-26T12:39:00.707 に答える