Skip to content

0. Techniques

Bilal edited this page Aug 14, 2017 · 2 revisions

You can save data using entity framework in 2 ways

1. Normal way

        public ActionResult Save(BlogViewModel blogViewModel)
        {
            Blog blog = _dbContext.Blogs.Find(blogViewModel.Id);

            blog.Description = blogViewModel.Description;

            blog.Title = blogViewModel.Title;

            _dbContext.SaveChanges();

            return View();
        }

2. Manually attaching entities

        public ActionResult Save(Blog blog)
        {
            _dbContext.Blogs.Attach(blog);
            _dbContext.Entry(blog).State = EntityState.Modified;

            _dbContext.SaveChanges();

            return View();
        }

In this pattern, TEDB wont work by default. You will have to set

GlobalTrackingConfig.DisconnectedContext = true;

on application startup.

Clone this wiki locally