我遇到了EF核心问题。
当我想在.Net核心上使用add-migration时,我收到此错误
"Could not load assembly 'DataAccess'. Ensure it is referenced by the startup project 'DataAccess'
。
我的项目已经在.netCore上的class.library和控制台应用上进行了测试。
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);
}
}
答案 0 :(得分:0)
我们应该以x64模式迁移。