none
EF 4.1 and Concurrency Question RRS feed

  • Question

  • Scenario's:
    1. WCF using EF 4.1 Code First as data layer; clients get the data as a result of calling the WCF service methods. How is/can concurrency be handled (another client gets the same data performs an update ...)?

    2. MVC 3 instead of passing the 'real' Model to the Views I pass a ViewModel to the Views. How is/can concurrency be handled (another client gets the same data performs an update ...)?

    Thanks.


    Tuesday, August 9, 2011 8:55 AM

Answers

  • Hi GuyD,

    Welcome!

    There are database wins and client wins. In EF4.1 we can use Reload method to handle the optimistic concurrency, or we can DbPropertyValues objects to set CurrentValues. The more information in this Blog.

    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.

    Wednesday, August 10, 2011 7:08 AM
    Moderator
  • Hi Guy,


    Supposing you are aware of the ConcurrencyToken in EF;

    With both scenario's, the same principle applies:
    If you're exposing data to a client (be it a WCF client, be it a MVC ViewModel),  you'll have to make sure that the ConcurrencyToken is transferred to the client.

     

    For instance, for the WCF client story, suppose you are working with a Person Entity, with a ConcurrencyToken.
    If you pass a PersonDto to the client, with some properties of the Person, you'll have to include the ConcurrencyToken on the 
    PersonDto.

    Whenever you save the PersonDto (using a WCF service again), it will be mapped to a Person, the ConcurrencyToken will be set, 
    and an exception will occur if anybody else changed the same data.Furthermore, depending on how much state you keep on your client, you'll have to update the ConcurrencyToken on the client after every save.


    Regards,
    Koen 


    Wednesday, August 10, 2011 3:00 PM

All replies

  • Hi GuyD,

    Welcome!

    There are database wins and client wins. In EF4.1 we can use Reload method to handle the optimistic concurrency, or we can DbPropertyValues objects to set CurrentValues. The more information in this Blog.

    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.

    Wednesday, August 10, 2011 7:08 AM
    Moderator
  • Hi Guy,


    Supposing you are aware of the ConcurrencyToken in EF;

    With both scenario's, the same principle applies:
    If you're exposing data to a client (be it a WCF client, be it a MVC ViewModel),  you'll have to make sure that the ConcurrencyToken is transferred to the client.

     

    For instance, for the WCF client story, suppose you are working with a Person Entity, with a ConcurrencyToken.
    If you pass a PersonDto to the client, with some properties of the Person, you'll have to include the ConcurrencyToken on the 
    PersonDto.

    Whenever you save the PersonDto (using a WCF service again), it will be mapped to a Person, the ConcurrencyToken will be set, 
    and an exception will occur if anybody else changed the same data.Furthermore, depending on how much state you keep on your client, you'll have to update the ConcurrencyToken on the client after every save.


    Regards,
    Koen 


    Wednesday, August 10, 2011 3:00 PM
  • 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.

    Saturday, August 20, 2011 9:19 AM
    Moderator