網站首頁 編程語言 正文
在.NET Core 項目鐘(類庫),使用Entity Framework,建立模型生成數據庫時,失敗
Could not load assembly 'xxx'. Ensure it is referenced by the startup project 'xxx'.
改成 64 位即可
假設 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 上面改,要到 項目目錄下更改 csproj 文件
ps
有了模型后,即可通過遷移創建數據庫。 運行 dotnet ef migrations add InitialCreate 以為遷移搭建基架,并為模型創建一組初始表。 運行 dotnet ef database update 以將新遷移應用到數據庫。 在應用遷移之前,此命令可創建數據庫。
原文鏈接:https://www.cnblogs.com/whuanle/p/10578319.html
相關推薦
- 2022-03-24 c++中的bind使用方法_C 語言
- 2022-08-02 C#中的multipart/form-data提交文件和參數_C#教程
- 2022-11-18 Python實現常見數據格式轉換的方法詳解_python
- 2022-06-16 golang?validator庫參數校驗實用技巧干貨_Golang
- 2022-12-30 解決React報錯The?tag?is?unrecognized?in?this?browser_R
- 2022-08-07 Go?gRPC超時控制Deadlines用法詳解_Golang
- 2022-11-11 Android學習之菜單的使用方法_Android
- 2022-05-13 數據結構學習筆記——順序存儲結構實現棧
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支