Click here to Skip to main content
15,897,291 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do you equate:
C#
db.Data1 = del.thistable;???

This works:
C#
del.thistable= db.Data1.ToList();

How do you do the reverse?
XML
public class HomeController : Controller
{
    private testContext db = new testContext();
    private DeleteModel del = new DeleteModel();
    public ActionResult Delete(int testID)
    {
        del.thistable= db.Data1.ToList();
        del.thistable.Remove(del.thistable.SingleOrDefault(o => o.testID == testID));
        db.Data1 = del.thistable;???
    }
}

Class1.cs
XML
public class Table1
   {
       [Key]
       public int testID { get; set; }
       public string datetime { get; set; }
       public string col1 { get; set; }
       public string col2 { get; set; }
       public string col3 { get; set; }
   }
   public class DeleteModel
   {
       public string errorcode { get; set; }
       public List<Table1> thistable { get; set; }
   }
   public class testContext : DbContext
   {
       public DbSet<Table1> Data1 { get; set; }
   }
Posted

1 solution

Try replacing your Delete method with the following and you should be good to go.


C#
public ActionResult Delete(int testId)
   {
            var table1 = new Table1() { testID = testId };
           db.Entry(table1).State=EntityState.Deleted;

              db.SaveChanges();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900