【发布时间】:2015-10-27 21:39:58
【问题描述】:
我正在通过迁移运行数据库更新,但 EF 正在使用我的连接字符串的名称创建数据库,而不是使用数据库的名称创建。
正确的做法是使用 METIS 名称创建数据库,但创建为 MetisConnectionString。
我做错了什么?
app.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionString>
<add name="MetisConnectionString" connectionString="Server=.\sqlexpress;Database=METIS;User ID=metis_usr;Password=metis_usr;" providerName="System.Data.SqlClient" />
</connectionString>
<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>
</configuration>
DataContext.cs
public class MetisDataContext : DbContext
{
public MetisDataContext()
: base("MetisConnectionString")
{
Configuration.LazyLoadingEnabled = false;
Configuration.ProxyCreationEnabled = false;
}
public DbSet<User> Users { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new UserMapping());
}
}
【问题讨论】:
-
你看到this question了吗?
-
@HenkHolterman 我看到了,但我不想相信它。我已经看到几个代码,ConnectionString 名称位于基础上。但它奏效了!也找到了这个链接msdn.microsoft.com/en-us/data/jj592674.aspx
标签: c# entity-framework migration entity-framework-6 entity-framework-migrations