简体   繁体   中英

How to access inherited members of derived class when instantiated in a different project

I have a solution in Visual Studio 2013 (Community Edition) that contains multiple projects, as follows:

  1. Project 1:

    In Project 1 I have defined a class that derives from the DbContext class of Entity Framework. It's defined along the lines of the following:

     public class MyContext : DbContext { public DbSet<EntityClass> EntitySet {get; set; } } 
  2. Project 2:

    I also have a Console Application project inside of my solution that references Project 1.

    When I create an instance of MyContext inside of Project 2 I cannot access the members inherited by MyContext from the DbContext class without adding a reference to Entity Framework and a using directive to the System.Data.Entity namespace.

Is there anyway to be able to access the members my derived context class have inherited from DbContext in Project 2 without:

a. Adding a reference to Entity Framework and writing a using directive for the System.Data.Entity namespace in a code file in Project 2; Or

b. Manually exposing each public member of DbContext in my derived context class?

No, That is not possible. Your project1 reference is depend upon other reference. You need to add all dependent reference under project2.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM