none
entity framework 4 update RRS feed

  • Question

  • In my ASP.net api service I use entity framework to send out a list of objects to client.  I would like to post back to service one modified object and have entity framework 4 update the corresponding row in database.

    Can't seem to get it working. Must be very obvious so apologies if it is.

    Regards.

     

    Paul


    Saturday, October 13, 2012 3:26 PM

Answers

  • Managed to solve problems enity framework 4 is a bit awkward to use so took the plunge and went to .net4.5. 

    Now I use EF 5 which is much easier to use. Basically:

      // POST api/values
            public void Post(myEntity objdisconnectedAndModified)
            {
                myEntities ctx = new myEntities();
                ctx.Entry(objdisconnectedAndModified);
                ctx.Entry(objdisconnectedAndModified).State = System.Data.EntityState.Modified;
                ctx.SaveChanges();
            }

    It really very elegant well done MS.


    Paul

    • Marked as answer by PAUL stanley Monday, October 15, 2012 6:23 PM
    Monday, October 15, 2012 6:23 PM

All replies

  • Hi Paul,

    Welcome to the MSDN forum.

    Do you encounter any error? If so, could you please let me know the specific error message?

    Would you let me know which specific step or method you have problem with? If you provide some code snippet, it would be nice.

    Best Regards,


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us

    Monday, October 15, 2012 9:03 AM
  • Managed to solve problems enity framework 4 is a bit awkward to use so took the plunge and went to .net4.5. 

    Now I use EF 5 which is much easier to use. Basically:

      // POST api/values
            public void Post(myEntity objdisconnectedAndModified)
            {
                myEntities ctx = new myEntities();
                ctx.Entry(objdisconnectedAndModified);
                ctx.Entry(objdisconnectedAndModified).State = System.Data.EntityState.Modified;
                ctx.SaveChanges();
            }

    It really very elegant well done MS.


    Paul

    • Marked as answer by PAUL stanley Monday, October 15, 2012 6:23 PM
    Monday, October 15, 2012 6:23 PM