English 中文(简体)
为什么我们需要在消费者项目中增加提及某组图书馆项目继承的集会?
原标题:Why do we need to add a reference to an assembly, from which a class library project inherits, into a consumer project?

我的解决办法包括两个项目:

  • a class library project (named as DataAccess) that defines a class (named as MyContext) inheriting from DbContext. As DbContext is defined in EntityFramework.dll assembly, 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 the DataAccess class 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 to EntityFramework.dll into 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.

最佳回答

由于<代码>MyContext中的许多行为从实体框架的基类中继承。 如果您将这些方法(例如SaveChanges(>)从中删除, 试验就需参考该方法界定的类别图书馆。

如果你只能使用您的班级图书馆界定的<代码>MyContext,我认为你可以不提及基类。

问题回答

Because otherwise EntityFramework.dll wont get copied to the output directory when you build your project and your library won t be able to access it.

如果你能够将<代码>EntityFramework.dll纳入你的图书馆(直线查询——和“财产”),那么你就不必提及你提出的假释申请。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签