1

我正在尝试使用 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());
        }
    }
4

0 回答 0