Domanda

I have 2 projects: X and Y. Project X is a class lib that references, lets say, EF 6. Project Y as a console app that references X. Why do i get a cannot load dependency exception if i do not add, lets say, EF 6 to project Y? Is there a way to "carry" those references to project Y?

The idea here is that Y should not know about EF-6, not to say its dependencies!

Nessuna soluzione corretta

Altri suggerimenti

You are very probably exposing classes to Y that inherit from Entity Framework, most probably your Entities, your Context if project Y uses that, etc.

Therefore, project Y needs to reference Entity Framework, because it cannot otherwise resolve the classes (base properties, logic) that your classes inherit from.

The only way to hide Entity Framework from Y is to make it completely independent of it. So for instance you may create a service class in project X that project Y calls, and this class' methods does not expose any classes from Entity Framework, nor any classes that inherit from classes in Entity Framework. You can do that by creating your own entities that you then map to from queries in Entity Framework etc.

Another way is to hide project X behind a webservice (WCF). Then project Y calls the webservice, which calls the logic in project X. The WCF webservice exposes nothing from Entity Framework, so your project Y does not need any references to it.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top