- 59
- 0
按照教程
https://www.cnblogs.com/yjmyz...
“System.IO.FileLoadException”类型的未经处理的异常在 mscorlib.dll 中发生其他信息: 未能加载文件或程序集“Oracle.ManagedDataAccess.EntityFramework,
Version=6.122.1.0, Culture=neutral,
PublicKeyToken=89b483f429c47342”或它的某一个依赖项。找到的程序集清单定义与程序集引用不匹配。 (异常来自
HRESULT:0x80131040)
可以读数据但是能不能创建表。
- 共 0 条
- 全部回答
-
心痛的网名繁体字 普通会员 1楼
在EF6 (Entity Framework 6) 的 Code First 调试和错误排查中,以下是一些可能的解决方案和错误代码:
-
Entity Framework Version Compatibility Problem: 如果EF6使用了不兼容的Entity Framework版本,如7.0.1或更高版本,可能会引发Code First错误。确保你的EF6安装在正确的版本,可以使用以下命令更新:
Update-Package Entity Framework -Version 7.0.1 -
Missing dependencies or missing assemblies: 如果你的项目中包含的EF6依赖项或依赖项的 assemblies 包装不完整,可能会导致代码 First 出现错误。确保你的项目包含以下依赖项:
csharp <dependentAssembly> <assemblyIdentity name="Entity Framework" publicKeyToken="6598530050101e49" culture="neutral"/> <bindingRedirect location="YourEF6Location/YourEF6Version.dll" /> </dependentAssembly>
请将
YourEF6Location替换为你的EF6安装目录,将YourEF6Version.dll替换为你的EF6安装的版本文件(例如,YourEF6Version.dll或EF6.SqlClient.dll)。- ASP.NET Core Entity Framework Configuration Error:
If you are using ASP.NET Core with EF6 and you have a configuration error, it could cause the Code First pipeline to fail. Make sure you have the correct EF Core configuration set up for your project, and it includes the necessary Entity Framework assemblies and settings.
csharp <configuration> <appsettings> <add key="EntityFramework.DefaultConnectionFactory" value="System.Data.SqlClient.SqlConnectionFactory" /> <add key="EntityFramework.UseSqlServer" value="true" /> <add key="EntityFramework.ConnectionStrings" value="your_connection_string" /> </appsettings> </configuration>
If your project is using Entity Framework Core v3, you will need to replace
System.Data.SqlClient.SqlConnectionFactorywithSystem.Data.Entity.SqlServer.SqlConnectionFactoryandyour_connection_stringwith your EF Core connection string.- Incompatible Database Provider:
If your project is using an incompatible database provider like SQLite or SQL Server, the EF6 Code First pipeline may fail due to database-specific features or constraints. Make sure your project is using a compatible database provider, such as SQLite or SQL Server.
<entityFramework> <defaultConnectionFactory type="System.Data.SqlClient.SqlConnectionFactory" /> <providers> <provider invariantName="System.Data.SqlClient" type="System.Data.SqlClient.SqlProvider" /> </providers> </entityFramework>
If you are using Entity Framework Core v2, you will need to specify the
providerInvariantNameparameter to specify the database provider to use. 5. Database Model Changes: If your project is using an updated database model that requires a specific EF6 change, such as changes to entity properties, associations, or relationships, the Code First pipeline may fail due to incompatibility with the existing EF6 model. To handle this, you can create a migration script that updates the database model to match the new version of EF6, or you can manually modify the database schema in your application.csharp Create-Database migrator -Target Database=my_new_db -DatabaseModelPath my_new_db/models.cs -OutputMigrationFile migration.up.mdfAfter creating the migration file, run the migration script using the following command:
.\migrations\up.mdf- Use of Unrecognized Entity Framework Database Model Version:
If your database model is using an older version of Entity Framework, the Code First pipeline may fail due to the lack of support for the new EF6 version. To resolve this, you can specify the appropriate database model version in your EF6 configuration or in the database model itself.
For example, in an ASP.NET Core application, you can use the
Modelssection of yourStartup.csfile to specify the database model version:csharp public void ConfigureServices(IServiceCollection services) { // ... your other configuration and services ... services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer( "your_connection_string", // specify the EF Core database model version new SqlClientSettings() .DatabaseModelVersion = "7.0.1" .EntityFrameworkVersion = "6.0.0" // or your EF Core version .DefaultConnectionFactory = "System.Data.SqlClient.SqlConnectionFactory" .DefaultConnectionString = "your_connection_string" // or your EF Core connection string )); }
Alternatively, you can include the necessary
EntityModelandDbContextclasses in your database model, and specify the database model version in theAddDbContextmethod: ```csharp public class ApplicationDbContext : DbContext { public DbSetProducts { get; set; } public DbSet Orders { get; set; } public DbSet OrderItems { get; set; } } public class Product { public int Id { get; set; } public string Name { get; set; } public decimal Price { get; set; } } public class Order { public int Id { get; set; } public string CustomerName { get; set; } public decimal TotalPrice { get; set; } }
public class OrderItem { public int Id { get; set; } public decimal Quantity { get; set; } public decimal PricePerUnit { get; set; } } ```
Ensure that you replace
your_connection_stringandyour_entityframework_versionwith your actual database connection string and the version of Entity Framework you are using.-
No DbContext configured: If your project is missing a DbContext, the Code First pipeline will fail due to a missing
DbContextclass or property. Ensure that you have aDbContextclass that inherits fromDbContextand implements theOnModelCreatingmethod to configure your EF6 model. ```csharp public class MyDbContext : DbContext { public DbSetProducts { get; set; } public DbSet Orders { get; set; } public DbSet OrderItems { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity
() .HasKey(p => p.Id); modelBuilder.Entity () .HasKey(o => o.Id); modelBuilder.Entity () .HasKey(i => i.Id); modelBuilder.Entity () .Property(p => p.Name).HasConversion( typeof(String).ToMemberName(), typeof(String).ToDatabaseColumn() ); modelBuilder.Entity () .Property(o => o.CustomerName).HasConversion( typeof(String).ToMemberName(), typeof(String).ToDatabaseColumn() ); modelBuilder.Entity () .Property(i => i.Quantity).HasConversion( typeof(Int32).ToMemberName(), typeof(Int32).ToDatabaseColumn() ); modelBuilder.Entity () .Property(i => i.PricePerUnit).HasConversion( typeof(decimal).ToMemberName(), typeof(decimal).ToDatabaseColumn() ); } } ```
This example defines a
MyDbContextclass withOnModelCreatingmethod that configures the EF6 model using custom conversions for entity properties. Make sure you replacemy_new_dbwith your actual database name andmy_new_db/models.cswith the path to your database model file.-
Custom Model Mapping Not Defined: If you have defined custom model mappings in your
DbContextclass, but they are not being mapped in the Code First pipeline, the pipeline may fail due to missing or invalid mapping. To fix this, make sure you have added theOnModelCreatingmethod to yourDbContextclass and configured theOnModelCreatingmethod to map your custom model classes to the database table(s) using theToModelMapmethod. ```csharp public class MyDbContext : DbContext { public DbSetProducts { get; set; } public DbSet Orders { get; set; } public DbSet OrderItems { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity
() .HasKey(p => p.Id); modelBuilder.Entity () .HasKey(o => o.Id); modelBuilder.Entity () .HasKey(i => i.Id); modelBuilder.Entity () .Property(p => p.Name).HasConversion( typeof(String).ToMemberName(), typeof(String).ToDatabaseColumn() ); modelBuilder.Entity () .Property(o => o.CustomerName).HasConversion( typeof(String).ToMemberName(), typeof(String).ToDatabaseColumn() ); modelBuilder.Entity () .Property(i => i.Quantity).HasConversion( typeof(Int32).ToMemberName(), typeof(Int32).ToDatabaseColumn() ); modelBuilder.Entity () .Property(i => i.PricePerUnit).HasConversion( typeof(decimal).ToMemberName(), typeof(decimal).ToDatabaseColumn() ); modelBuilder.Entity () .
-
- 扫一扫访问手机版
回答动态

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器更新之后。服务器里面有部分玩家要重新创建角色是怎么回事啊?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题函数计算不同地域的是不能用内网吧?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题ARMS可以创建多个应用嘛?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题在ARMS如何申请加入公测呀?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题前端小程序接入这个arms具体是如何接入监控的,这个init方法在哪里进行添加?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器刚到期,是不是就不能再导出存档了呢?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器的游戏版本不兼容 尝试更新怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器服务器升级以后 就链接不上了,怎么办?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器转移以后服务器进不去了,怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器修改参数后游戏进入不了,是什么情况?预计能赚取 0积分收益
- 回到顶部
- 回到顶部
