Nei*_*l W 12 entity-framework code-first ef-migrations entity-framework-6
我创建了一个带有3个实体类的C#类库和一个用于代码优先生成数据库的DbContext.所有版本都很顺利.我创建了一个单独的测试库,带有DbContext类的类库已按预期运行.
现在,我想使其中一个字段成为必需字段并遵循代码优先约定,我在实体类中为属性添加了[Required]属性.下一步是启用迁移.
我进入了软件包管理器控制台,输入了"enable-migrations"并且... bang ..." 无法加载指定的元数据资源 ".
作为参考,我的DbContext类包括:
public OrganisationsContext()
: base("Leegz_Entities_Organisations")
{
this.Configuration.LazyLoadingEnabled = false;
this.Configuration.ProxyCreationEnabled = false;
}
public DbSet<Organisation> Organisations { get; set; }
public DbSet<Member> Members { get; set; }
public DbSet<LeegzUser> LeegzUsers { get; set; }
Run Code Online (Sandbox Code Playgroud)
我的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>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<connectionStrings>
<add name="Leegz_Entities_Organisations" connectionString="data source=NEIL-INSPIRON\NEILDEV;initial catalog=TheLeegz;integrated security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="Leegz.Entities.Organisations.DbSecuritySchema" value="Leegz.Entities.Organisations"/>
</appSettings>
</configuration>
Run Code Online (Sandbox Code Playgroud)
我已经看到了很多关于这个主题的线程,但它们似乎都在谈论EDMX模型文件的引用元素中的错误.但是,因为我已经使用了代码优先,我没有模型(也许我在这里错过了一步),所以我在连接字符串中看到的关于EDMX信息的建议似乎不大适用于我.
请问有什么想法吗?
Max*_*ime 24
我有类似的问题,但结果不同.由于调试花费了太多时间,因此这里有一些提示.
Enable-Migrations命令,它应该正常工作.模型第一个连接字符串示例
<add name="MyContext"
connectionString="metadata=res://*/MyModel.csdl|res://*/MyModel.ssdl|res://*/MyModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.;initial catalog=MY_DB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
Run Code Online (Sandbox Code Playgroud)
代码第一个连接字符串示例
<add name="MyContext"
connectionString="Data Source=.;Initial Catalog=MY_DB;Integrated Security=True;MultipleActiveResultSets=True"
providerName="System.Data.SqlClient"/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8892 次 |
| 最近记录: |