EF6错误168 ProviderManifest实例

时间:2013-11-05 05:54:02

标签: c# asp.net-mvc entity-framework

当我创建表格和关系的实体视图时,我收到错误 我正在使用EF6和我在编写DbContext类的教程。没有人知道为什么我会得到这个错误以及如何解决它。

Error 168: The provider did not return a ProviderManifest instance. 
The provider did not return a ProviderManifest instance.C:\....\BlogContext.edmx                            Miscellaneous Files

  <configSections>
      <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />


  <connectionStrings>    
    <add name="BlogContext" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-BlogDbContext-20131105145750;User Instance=false;Persist Security Info=False;Integrated Security=SSPI; AttachDBFilename=|DataDirectory|\aspnet-BlogDbContext-20131105145750.mdf" providerName="System.Data.SqlClient" />
  </connectionStrings>

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

    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, 
           EntityFramework.SqlServer" />
    </providers>
</entityFramework>


[DbConfigurationType(typeof(EntityFrameworkDbConfiguration))]
public partial class BlogContext : DbContextBase
{
    public BlogContext()
        : base("BlogContext")
    {
        Database.SetInitializer<BlogContext>(null);
        Configuration.ProxyCreationEnabled = false;
    }

    public new IDbSet<T> Set<T>() where T : class
    {
        return base.Set<T>();
    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        modelBuilder.Configurations.Add(new CategoryMap());
        modelBuilder.Configurations.Add(new PostMap());                       
        modelBuilder.Configurations.Add(new TagMap());
        modelBuilder.Configurations.Add(new PostTagMap());
        modelBuilder.Configurations.Add(new CommentMap());            
    }
}


    public class DbContextBase: DbContext, IDbContext
{
    public readonly Guid _instanceId;


    public DbContextBase(string nameOrConnectionString)
        : base(nameOrConnectionString)
    {
        _instanceId = Guid.NewGuid();
    }

    public Guid InstanceId
    {
        get { return _instanceId; }
    }

    public void ApplyStateChanges()
    {
        foreach (DbEntityEntry dbEntityEntry in ChangeTracker.Entries())
        {
            var entityState = dbEntityEntry.Entity as IObjectState;
            if (entityState == null)
                throw new InvalidCastException("All entities must implement the IObjectState interface, " +
                    "this interface must be implemented so each entities state can explicitly determined when updating graphs.");

            dbEntityEntry.State = StateHelper.ConvertState(entityState.State);
        }
    }

    public new IDbSet<T> Set<T>() where T : class
    {
        return base.Set<T>();
    }

    public override int SaveChanges()
    {
        ApplyStateChanges();
        return base.SaveChanges();
    }

    public override Task<int> SaveChangesAsync()
    {
        ApplyStateChanges();
        return base.SaveChangesAsync();
    }

    public override Task<int> SaveChangesAsync(System.Threading.CancellationToken cancellationToken)
    {
        ApplyStateChanges();
        return base.SaveChangesAsync(cancellationToken);
    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
        base.OnModelCreating(modelBuilder);
    }
}

0 个答案:

没有答案