1

I'm trying to set up an EF Code-Only scenario with the AdventureWorksLT database but it doesn't work.

I have this error:

Invalid object name 'dbo.BuildVersion'

The error comes from an executeReader in an inner method of the EntityFramework.dll with that query:

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

Of course the query is correct and returns a result.

So, why do I have this exception?

Here is the code (I remove all the conventions):

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();
        }
    }

And ...

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


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

            modelBuilder.Configurations.Add(new BuildVersionConfiguration());
        }
    }
Kevin
  • 53,822
  • 15
  • 101
  • 132
pellea
  • 359
  • 3
  • 21

0 Answers0