微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

entity-framework-6 – Entity Framework种子方法异常

我正在使用Entity Framework 6和针对Oracle数据库的MVC5 webapi2项目.

我试图在Seed方法添加一些ApplicationRoles,但是当我执行update-database时,我得到以下异常:

Running Seed method.
System.Runtime.Serialization.SerializationException: Type is not resolved for member ‘Oracle.ManagedDataAccess.Client.OracleException,Oracle.ManagedDataAccess,Version=4.121.2.0,Culture=neutral,PublicKeyToken=89b483f429c47342’.
at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration,Boolean force)
at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__displayClass2.<.ctor>b__0()
at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
Type is not resolved for member ‘Oracle.ManagedDataAccess.Client.OracleException,PublicKeyToken=89b483f429c47342’.

我在Seed方法中的代码

var roleStore = new RoleStore<IdentityRole>(context);
var roleManager = new RoleManager<IdentityRole>(roleStore);

if (!context.Roles.Any(r => r.Name == "USER"))
{
    var role = new IdentityRole("USER");
    roleManager.Create(role);
}

update-database正在创建我的表而没有任何问题,它只是Seed方法有问题.

有没有人对这个问题有什么建议?

谢谢.

解决方法

将Oracle.ManagedDataAccess.dll安装到GAC解决了我的问题.如果您在计算机上安装了可能是原因的Oracle客户端或Oracle数据库.

C:\Windows\system32>cd E:\smn\packages\Oracle.ManagedDataAccess.12.1.021\lib\net40

C:\Windows\system32>e:

E:\smn\packages\Oracle.ManagedDataAccess.12.1.021\lib\net40>"C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\gacutil.exe" /i Oracle.ManagedDataAccess.dll
Microsoft (R) .NET Global Assembly Cache Utility.  Version 4.0.30319.33440
copyright (c) Microsoft Corporation.  All rights reserved.

Assembly successfully added to the cache

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐