Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Net Core uses EF to generate database how to solve the problem

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces the relevant knowledge of "how to solve database errors generated by .NET Core using EF". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to solve database errors generated by .NET Core using EF" can help you solve the problem.

In the .NET Core project clock (class library), when using Entity Framework to build the model and generate the database, it failed.

Could not load assembly 'xxx'. Ensure it is referenced by the startup project 'xxx'.

Just change it to 64 bit.

Suppose the ef code

Public class ApplicationDbContext: IdentityDbContext {public ApplicationDbContext (DbContextOptions options): base (options) {} public virtual DbSet Users {get; set;} public virtual DbSet Roles {get; set;} public virtual DbSet Groups {get; set;} public virtual DbSet GroupRoles {get; set;} public virtual DbSet Logs {get; set;} public virtual DbSet LogDetails {get; set;} protected override void OnConfiguring (DbContextOptionsBuilder optionsBuilder) = > optionsBuilder.UseSqlServer (@ "Data Source=. Initial Catalog=DotNetCore;Persist Security Info=True;User ID=sa;Password=25423456; "); protected override void OnModelCreating (ModelBuilder modelBuilder) {modelBuilder.Entity () .HasOne (d = > d.Group) .WithMany (t = > t.Users) .HasForeignKey (d = > d.GroupId) .OnDelete (DeleteBehavior.Cascade);}}

Change it to 64-bit method. Don't change it on VS. Go to the project directory to change the csproj file.

Ps

Once you have the model, you can create the database through migration. Run dotnet ef migrations add InitialCreate to build a base for the migration and create a set of initial tables for the model. Run dotnet ef database update to apply the new migration to the database. This command creates the database before applying the migration. This is the end of the introduction to "how to solve the problem of the database generated by the .NET Core using EF". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report