ASP.NET MVC:在程序集中找不到上下文类型
这是我的第一个asp.net mvc项目。 我使用EF代码第一种方法并创建了一个单独的类库来编写我的模型和上下文。 我还在mvc项目中引用了类库。 但是,当我尝试启用迁移时,在创建了更多新模型之后,它给了我一个错误。 我还尝试了这里提到的所有可能的解决方案: 在程序集中找不到上下文类型。 ASP.NET MVC4
问题仍然存在。 我错过了什么吗?
这是Context Class的代码:
using System; using System.Collections.Generic; using System.Data.Entity; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data.Entity.ModelConfiguration.Conventions; using FYPPharmAssistant.Domain.Models; namespace FYPPharmAssistant.Domain.DAL { public class MyContext : DbContext { public MyContext() : base("MyConnectionString") { } public DbSet GenericNames { get; set; } public DbSet Items { get; set; } public DbSet Manufacturers { get; set; } public DbSet Stocks { get; set; } public DbSet PaymentStatus { get; set; } public DbSet Purchase { get; set; } public DbSet PurchaseItems { get; set; } public DbSet Suppliers { get; set; } //avoids pluralizing table names protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Conventions.Remove(); } } }
我的web.config :
<!-- -->
这可能对将来的某些人有所帮助。 所以我再写一遍。
我刚从PackageManager控制台的下拉列表中将 Default Project更改为FYPPharmacyAssistant.Domain,问题解决了。 FYPPharmacyAssistant.Domain是我的单独项目或类库,由我的所有实体和数据库上下文类组成。
上下文需要与迁移配置位于同一项目中