.NET Core使用EF生成數(shù)據(jù)庫出錯的解決方法
在.NET Core 項(xiàng)目鐘(類庫),使用Entity Framework,建立模型生成數(shù)據(jù)庫時,失敗
Could not load assembly 'xxx'. Ensure it is referenced by the startup project 'xxx'.
改成 64 位即可
假設(shè) ef 代碼
public class ApplicationDbContext : IdentityDbContext<User> { public ApplicationDbContext(DbContextOptions options) : base(options) { } public virtual DbSet<User> Users { get; set; } public virtual DbSet<Role> Roles { get; set; } public virtual DbSet<Group> Groups { get; set; } public virtual DbSet<GroupRole> GroupRoles { get; set; } public virtual DbSet<Log> Logs { get; set; } public virtual DbSet<LogDetail> 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<User>() .HasOne(d => d.Group) .WithMany(t => t.Users) .HasForeignKey(d => d.GroupId) .OnDelete(DeleteBehavior.Cascade); } }
改成 64位的方法,不要在 VS 上面改,要到 項(xiàng)目目錄下更改 csproj 文件
ps
有了模型后,即可通過遷移創(chuàng)建數(shù)據(jù)庫。 運(yùn)行 dotnet ef migrations add InitialCreate 以為遷移搭建基架,并為模型創(chuàng)建一組初始表。 運(yùn)行 dotnet ef database update 以將新遷移應(yīng)用到數(shù)據(jù)庫。 在應(yīng)用遷移之前,此命令可創(chuàng)建數(shù)據(jù)庫。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Entity?Framework?Core生成數(shù)據(jù)庫表
- Entity Framework Core對Web項(xiàng)目生成數(shù)據(jù)庫表
- Entity Framework Core使用控制臺程序生成數(shù)據(jù)庫表
- Entity Framework使用Code First模式管理數(shù)據(jù)庫
- 使用EF的Code?First模式操作數(shù)據(jù)庫
- EFCore 通過實(shí)體Model生成創(chuàng)建SQL Server數(shù)據(jù)庫表腳本
- Entity?Framework?Core基于數(shù)據(jù)模型創(chuàng)建數(shù)據(jù)庫
相關(guān)文章
MAUI使用Maui.Graphics.Controls繪制控件詳解
本文詳細(xì)講解了MAUI使用Maui.Graphics.Controls繪制控件的方法,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-02-02DataGridView多維表頭的實(shí)現(xiàn)方法
不過我自己還是擴(kuò)展了DataGridView,使之能制作出多維表頭。2013-04-04ASP.NET獲取各級目錄Server.MapPath詳解全
ASP.NET獲取各級目錄Server.MapPath詳解全,需要的朋友可以參考下。2011-12-12ASPX向ASCX傳值以及文本創(chuàng)建圖片(附源碼)
把用戶在TextBox輸入的文字創(chuàng)建為一個圖片,ASCX的ImageButton的ImageUrl重新指向這剛產(chǎn)生的圖片,接下來介紹下ASPX向ASCX傳值,感興趣的朋友可以參考下哈2013-03-03C#和asp.net中鏈接數(shù)據(jù)庫中參數(shù)的幾種傳遞方法實(shí)例代碼
這篇文章介紹了C#和asp.net中鏈接數(shù)據(jù)庫中參數(shù)的幾種傳遞方法實(shí)例代碼,有需要的朋友可以參考一下2013-10-10