Search code examples
databaseentity-frameworkc#-4.0entity-framework-5database-first

why the detached entity is modified successfully in entity framework 5?


my code is .

class Program
        {

            static NorthwindEntities context = new NorthwindEntities();

            static void Main(string[] args)
            {
       Order updateorder = new Order() { OrderID = 10256, ShipCountry = "444", ShipCity = "tehran" };            
                update(updateorder);
            }


            static public void update(Order updateorder)
            {

                context.Entry<Order>(updateorder ).State = EntityState.Modified;

                context.SaveChanges();

            }
        }

please help me , i confused why the detached entity is modified in database


Solution

  • the call to context.Entry<Order>(updateorder) attaches the object to EF.