为什么 TableAttribute 位于实体框架 Dll 中?
Table 属性(可用于将 POCO 类映射到正确的数据库名称/架构)位于 EntityFramework.dll 中是否有充分的理由?
这是否会阻止您创建一个仅包含您的实体而不依赖于特定数据访问技术的域项目?例如,如果我使用此属性,我不相信这些类可以移植到 Silverlight。
这是一个疏忽,还是我错过了什么?
我意识到我可以使用 Fluent API 来规避这个问题,但该属性似乎更适合此目的。
Is there a good reason why the Table attribute (which can be used to map a POCO class to the correct database name/schema) is in the EntityFramework.dll?
Doesn't this prevent you from creating a Domain project that simply contains your entities with no dependency on a specific data access technology? For example, if I use this attribute I don't believe the classes would be portable to Silverlight.
Is this an oversight, or am I missing something?
I realize I could use the fluent API to circumvent this, but the attribute seems preferable for this purpose.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为是因为 EF 4.1 中添加了 TableAttribute。它属于命名空间 System.ComponentModel.DataAnnotations,如果 EF 4.1 是常规 .NET Framework 的一部分,则可能已添加到 System.ComponentModel.DataAnnotations.dll 程序集中发布。但由于 EF 4.1 是独立于框架更新发布的,因此它们无法触及框架核心程序集。因此,它目前位于 EntityFramework.dll 中,但仍在 System.ComponentModel.DataAnnotations 命名空间中,因此在某种程度上独立于实体框架。也许它会随着下一个 .NET Framework 版本移至 System.ComponentModel.DataAnnotations.dll 中。
目前,如果您想使用 TableAttribute 装饰 POCO,则必须引用 EntityFramework.dll。只要您不在自定义程序集中使用“真正的”EF 内容(
DbContext
等),我就不会将其视为实体框架的依赖项。I think because the TableAttribute has been added in EF 4.1. It belongs to namespace
System.ComponentModel.DataAnnotations
and would probably have been added toSystem.ComponentModel.DataAnnotations.dll
assembly if EF 4.1 had been part of a regular .NET Framework release. But because EF 4.1 was released independently from a Framework update they couldn't touch the framework core assemblies. So, it is for now in EntityFramework.dll but still inSystem.ComponentModel.DataAnnotations
namespace, so somehow independent from Entity Framework. Maybe it will be moved intoSystem.ComponentModel.DataAnnotations.dll
with the next .NET Framework version.For now, if you want to decorate your POCOs with the TableAttribute you must reference EntityFramework.dll. I wouldn't consider this as dependency from Entity Framework as long as you don't use the "real" EF stuff (
DbContext
, etc.) in your custom assembly.这确实会给 Silverlight 带来问题。
对于那些在这一问题上苦苦挣扎的人,目前必须使用 Fluent API 来进行映射。
HTH。
This does cause a problem for Silverlight.
For those with struggling with this one you must, for the moment, use the fluent API to do the mapping.
HTH.