Autosave (SaveChanges in properties setters in code first entity) RRS feed

  • Question

  • How can I save entity changes directly in properties setters (in EntityFramework 4.1  an code first entity ) ?




    Thursday, July 21, 2011 11:20 AM

All replies

  • Hello,

    don't do that. It will create a lot of database roundtrips if you decide to modify multiple properties. Moreover it will make your entity dependent on DbContext which is in most cases considered as bad approach without separation of concerns. It will also break core functionality of the context - unit of work where multiple related changes are saved together in single transaction.

    Best regards,

    Thursday, July 21, 2011 10:02 PM
  • Thank you for your response.  In my scenario, it will be one property which will be infrequent changed (so database roundtrips will not be an issue).  Is any smartly way to resolve this scenario?


    Monday, July 25, 2011 5:58 AM
  • Hi,

    I am writing to check the status of the issue on your side.  Would you mind letting us know the result of the suggestions?

    If you need further assistance, please feel free to let me know.   I will be more than happy to be of assistance.

    Have a nice day.

    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, August 2, 2011 3:54 PM
  • Thank you Alan,

    I postponed the project in which i needed the scenario from this thread so resolving it is no more an issue for me.

    Best regards,


    Wednesday, August 3, 2011 6:14 AM