仅限EF代码:无效的对象名称'dbo.BuildVersion'

时间:2011-12-13 21:31:13

标签: entity-framework ef4-code-only

我正在尝试使用AdventureWorksLT数据库设置EF Code-Only方案,但它不起作用。

我有这个错误:

Invalid object name 'dbo.BuildVersion'

错误来自executeReader内部方法EntityFramework.dll的错误:

SELECT 
[Extent1].[SystemInformationID] AS [SystemInformationID], 
[Extent1].[Database Version] AS [Database Version], 
[Extent1].[VersionDate] AS [VersionDate], 
[Extent1].[ModifiedDate] AS [ModifiedDate]
FROM [dbo].[BuildVersion] AS [Extent1]

当然查询是正确的并返回结果。

那么,为什么我有这个例外?

这是代码(我删除了所有约定):

public class BuildVersionConfiguration : EntityTypeConfiguration<BuildVersion>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="BuildVersionConfiguration"/> class.
        /// </summary>
        public BuildVersionConfiguration()
        {
            this.ToTable("BuildVersion", "dbo");

            this.HasKey(e => new { e.SystemInformationId, e.DatabaseVersion, e.VersionDate, e.ModifiedDate });

            this.Property(e => e.SystemInformationId).HasColumnName("SystemInformationID").IsRequired();
            this.Property(e => e.DatabaseVersion).HasColumnName("Database Version").IsRequired();
            this.Property(e => e.VersionDate).HasColumnName("VersionDate").IsRequired();
            this.Property(e => e.ModifiedDate).HasColumnName("ModifiedDate").IsRequired();
        }
    }

而且......

public class MyContext : DbContext
    {
        public DbSet<BuildVersion> BuildVersion { get; set; }


        // Methods
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            // Remove conventions

            modelBuilder.Configurations.Add(new BuildVersionConfiguration());
        }
    }

1 个答案:

答案 0 :(得分:0)

不确定此link是否可以解决您的问题。问题看起来与面值相似。试一试,看看它是否解决了。