Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DeleteObject method is missing in Entity Framework 4.1

This is driving me crazy. I am getting error that

object doesn't contain definition for DeleteObject.

Here is my line of code that produces an error:

ctx.Tanks.DeleteObject(Tank);

I tried to reference another object from another edmx file that my friend has created and then everything is fine, DeleteObject exists. I don't think I miss any references in my project.

And project itself contains edmx file and I used DBContext to create POCOs.

Any ideas?

like image 209
bobetko Avatar asked May 27 '26 14:05

bobetko


2 Answers

The DbContext API defines DbSets not ObjectSets. DbSet has a Remove method not DeleteObject method. You need to first decide which API you are going to use. If it the ObjectContext or DbContext.

like image 145
Eranga Avatar answered May 30 '26 03:05

Eranga


  [HttpPost]
        public ActionResult Delete(IEnumerable<int> employeeIdsToDelete)
        {
            var lstemployee = _db.StudentEmployees.Where(x => employeeIdsToDelete.Contains(x.Id));
            foreach (var item in lstemployee)
            {
                _db.StudentEmployees.Remove(item);
            }
            _db.SaveChanges();

            return RedirectToAction("Index");
        }
like image 21
Torakami Avatar answered May 30 '26 03:05

Torakami



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!