简体   繁体   中英

Inserting and deleting Data using Entity Framework Issue

I am using Entity Framework to link my data to asp.net mvc application. The weird part is that I can read the records normally using the below GetALL function but none of the Insert and Delete are working. Is there any reason for that? I am wondering if there is any restriction on the database and how to fix it if any? Note that I am getting no error however it is saying create is successful and delete is successful as well.

 public IEnumerable<tbl_Category> GetALL()
        {
            return db.tbl_Category.ToList();
        }
        public tbl_Category GetByID(int Id)
        {
            return db.tbl_Category.Find(Id);
        }
        public void Insert(tbl_Category cat)
        {
            db.tbl_Category.Add(cat);
        }
        public void Delete(int Id)
        {
            tbl_Category cat = db.tbl_Category.Find(Id);
            db.tbl_Category.Remove(cat);
        }

我认为您必须在数据上下文上调用SubmitChanges()/ SaveChanges()。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM