My solution consists of two projects:
- a class library project (named as
DataAccess) that defines a class (named asMyContext) inheriting fromDbContext. AsDbContextis defined inEntityFramework.dllassembly, I need to add a reference to this assembly into this class library project. I have no confusion in this mechanism. - a console application project (named as
Tester) that consumes theDataAccessclass defined in the class library above. Adding a reference to the assembly of the class library above is understandable. Unfortunately, I cannot compile the solution until I add a reference toEntityFramework.dllinto this console application.
Why do we need to add a reference to an assembly, from which a class library project inherits, into a consumer project?
In my mental model, it is enough to only add a reference to DataAccess project assembly into Tester project and the chained references should be done automatically.
Because a lot of the behaviour in
MyContextis inherited from the base class in entity framework. If you call those methods (e.g.SaveChanges()) fromTester, theTesterapp needs a reference to the class library where the method is defined.If you would only access methods of
MyContextthat are defined in your class library, I think you could do without the reference to the base class.