public IActionResult Delete([FromBody] int id)
        {
            MyDetails data = _context.Set <MyDetails>().FirstOrDefault(c => c.Id == id);

            _context.Entry(data).State = Microsoft.EntityFrameworkCore.EntityState.Deleted;
            _context.SaveChanges();
            return(Ok(true));
        }
示例#2
0
 public static void Delete()
 {
     using (EntityModelContext context = new EntityModelContext())
     {
         Employee emp = context.Employees.Include(p => p.EmployeeDetail).Where(p => p.Id == 5).FirstOrDefault();
         context.Entry <Employee>(emp).State = EntityState.Deleted;
         context.SaveChanges();
     }
     Console.ReadLine();
 }
示例#3
0
 public static void Update()
 {
     using (EntityModelContext context = new EntityModelContext())
     {
         Employee emp = context.Employees.Where(p => p.Id == 5).FirstOrDefault();
         emp.Name = "Meera";
         context.Entry(emp).Property("CreatedDate").CurrentValue = DateTime.Now;
         context.SaveChanges();
     }
     Console.ReadLine();
 }
示例#4
0
        public static void Insert()
        {
            using (EntityModelContext context = new EntityModelContext())
            {
                Employee emp = new Employee
                {
                    Id   = 5,
                    Name = "Vishal",
                };
                context.Entry(emp).Property("CreatedDate").CurrentValue = DateTime.Now;

                context.Add(emp);
                context.SaveChanges();
            }
            Console.ReadLine();
            Console.Clear();
        }