none
LINQ -In Concurency checking, get data from database RRS feed

  • Question

  • Hi,

    When data is in concurrency, how can i get the value in db compare with the current value?

    It is not captured in objchangeconf.MemberConflicts, because the field itself is not conflict, is other field in conflict.

    example:
    user: userA_ID,
    desc: A

    user:userB_ID,
    desc: B

    in my project, it only detect conflict on desc field, but not user field.
    Is there a way to get the data 'userA_ID' when it is not captured in MemberConflicts?


    Friday, December 6, 2013 10:14 AM

Answers

  • >>But originally, before updated by second user, the last modified user is userA_ID as well.

    So the conflict actually does not occur.

    >>So can i conclude that if it is not captured in conflict, then i have no way to get the data?

    Have a try to use the Reload() method like below:

     Order orderold = db.Orders.FirstOrDefault();
     db.Entry(orderold).Reload();

    Since it will cover the old object, we need to define a template object to log the original object data.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, December 10, 2013 8:05 AM
    Moderator

All replies

  • Is user field a key perhaps?

    Miha Markic [MVP C#] http://blog.rthand.com

    Saturday, December 7, 2013 8:38 PM
  • It is not a key.

    But is it possible to get the value even thought it not captured in objchangeconf.MemberConflicts?

    What i mean is to get the whole object.
    Sunday, December 8, 2013 8:34 AM
  • Hello,

    Is it that the two records are one record exactly? May be like:

    ID:1

    user: userA_ID,

    desc: A

    ID:1

    user:userB_ID,

    desc: B

    >>it only detect conflict on desc field, but not user field.

    It is strange that because the ObjectChangeConflict.MemberConflicts will get a collection of objects that represent the discrepancies between the current values of the list item’s fields and the values they have in the database.

    If the ‘user’ and ‘desc’ have been changed, they should be both detected. I made a test and found that it would detect all changed fields. My test codes are like below:

    using (DataClasses1DataContext db = new DataClasses1DataContext()) { Order order = db.Orders.FirstOrDefault(); order.OrderName = "C001"; //db.Orders.InsertOnSubmit(order); try { db.SubmitChanges(ConflictMode.ContinueOnConflict); } catch (ChangeConflictException e) { foreach (ObjectChangeConflict objectChangeConflict in db.ChangeConflicts) { foreach (MemberChangeConflict memberChangeConflict in objectChangeConflict.MemberConflicts) {

    //do some operation

    } } } }

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, December 9, 2013 3:10 AM
    Moderator
  • yes, it is only one record, just updated by different user.
    I also find kind of weird, why it is not captured in conflict.
    But originally, before updated by second user, the last modified user is userA_ID as well.
    Could it be the root cause? even thought record already updated, submit changes by second user, but linq doesn't aware of this, and conclude the user is not changed?

    So can i conclude that if it is not captured in conflict, then i have no way to get the data?


    Monday, December 9, 2013 2:07 PM
  • >>But originally, before updated by second user, the last modified user is userA_ID as well.

    So the conflict actually does not occur.

    >>So can i conclude that if it is not captured in conflict, then i have no way to get the data?

    Have a try to use the Reload() method like below:

     Order orderold = db.Orders.FirstOrDefault();
     db.Entry(orderold).Reload();

    Since it will cover the old object, we need to define a template object to log the original object data.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, December 10, 2013 8:05 AM
    Moderator