Emmmanuel FIADUFE

Emmmanuel FIADUFE

  • 752
  • 1.2k
  • 57.8k

Entity Validation Error

Nov 25 2024 11:57 PM

Hello Team,

In my MVC C# controller, I have a method that bind item with DbDataSet called MyContext,

But any time I run the project I get the following error.

 

private MyContext db = new MyContext();
        public ActionResult Index()
        {
            var items = db.Items.Include(i => i.DrugGenericNames).Include(i => i.Manufacturer).OrderByDescending(i => i.ItemID);
            return View(items.ToList());
            
        }

 

 

 

public class MyContext : DbContext
    {
         public MyContext()
            : base("connectionString")
        {

        }
        public DbSet<DrugGeneric> DrugGenericNames { get; set; }
        public DbSet<Item> Items { get; set; }
        public DbSet<Manufacturer> Manufacturers { get; set; }
        public DbSet<Stock> Stocks { get; set; }
        public DbSet<tblSupplier> Suppliers { get; set; }
        public DbSet<tblPurchase> Purchases { get; set; }
        public DbSet<tblPurchaseItem> PurchaseItems { get; set; }
        public DbSet<tblNotification> Notifications { get; set; }
        public DbSet<SalesReturn> SalesReturns { get; set; }
        public DbSet<SalesReturnDetail> SalesReturnDetails { get; set; }
        public DbSet<Sales> Sales { get; set; }
        public DbSet<SalesItem> SalesItems { get; set; }
       
        public DbSet<tblUser> Users { get; set; }
        //avoids pluralizing table names in database
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
            

        }        
    }
    }
 


Answers (12)