Why is the TableAttribute in the Entity Framework Dll?

只愿长相守 提交于 2019-12-05 17:15:34

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 to System.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 in System.ComponentModel.DataAnnotations namespace, so somehow independent from Entity Framework. Maybe it will be moved into System.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.

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.

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<BankAccount>().ToTable("BankAccounts");
    modelBuilder.Entity<CreditCard>().ToTable("CreditCards");
}

HTH.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!