Failed to get metadata for "MyService.Entities.Email". A type initializer for "System.Data.Entity.Internal.AppConfig" threw an exception

I am testing a new beta version of Visual Studio 11 with MVC 4.0 and EF 4.3.1.

When I add the controller, I get the following message “Failed to get metadata for“ MyService.Entities.Email. ”The type initializer for“ System.Data.Entity.Internal.AppConfig "made an exception"

Repro

I have a basic solution having an Entities project (MyService.Entities) and an MVC project (MyService.Website).

In the Entities project, I have bare bones for the code first with a class for "Email" and a class for DbContext. Two classes look like this: EntitiesDb

   namespace MyService.Entities
{
    public class EntitiesDb : DbContext
    {
        public EntitiesDb(string nameOrConnectionString)
            : base(nameOrConnectionString)
        { }

        public EntitiesDb()
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            // Sets up the defaults for the model builder
            // Removes the metadata being written to the database, This is being depreciated anyhow 
            modelBuilder.Conventions.Remove<IncludeMetadataConvention>();

            // Sets the table names so that they are named as a none plural name 
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

            // Creates the database from scratch when it builds
            base.OnModelCreating(modelBuilder);
        }

        public DbSet<Email> Emails { get; set; }
    }
}

Email

namespace MyService.Entities
{
    public class Email
    {
        public Email()
        {
        }

        [Key, DatabaseGenerated(System.ComponentModel.DataAnnotations.DatabaseGeneratedOption.Identity)]
        public int EmailId { get; set; }
        public string Subject { get; set; }
        public string BodyHTML { get; set; }
    }
}

MyService.Entities MVC MyService.Website

<add name="EntitiesDb" connectionString="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=EntitiesDb;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />

MVC, :

  • > >
  • EmailController
  • /, Entity Framework
  • (MyService.Entities)
  • EntitiesDb (MyService.Entities)
  • Razor

" " MyService.Entities.Email ". " System.Data.Entity.Internal.AppConfig " "

, , , . , .

:

  • MVC.
  • Entities
  • - Visual Studio 11 , - .
  • ( EntityFramework 4.3.1.0)
  • ( ; o))

VS11? - ?

.

EDIT: EntitiesFramework NuGet, ​​.

+3
1

webconfig

<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory,    EntityFramework" />
<providers>
 </providers>
</entityFramework>
+1

All Articles