none
Delete a record in Entity Framework. RRS feed

  • Question

  • I have a command which can retrieve a record in the table.

    var x = iContext.myTable.

    First(i => i.FacilityID == facilityID && i.FileName == fileName);

    By checking it in the debugging, I found x is a row.
    I want to delete it from the table, how?

    I use EF 4.1.


    • Edited by ardmore Monday, January 28, 2013 4:57 PM
    Monday, January 28, 2013 4:57 PM

Answers

  • Hi ardmore;

    After retrieving the entity from the database as you did in your post you can mark the record for deletion as follows.

    iContext.myTable.Remove(x);

    Now when you are ready to update the database you need to do the following command.

    iContext.SaveChanges();

    At this point the record has been deleted from the database.

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by ardmore Tuesday, January 29, 2013 1:10 PM
    Monday, January 28, 2013 6:40 PM

All replies