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