locked
Data conflict resolution RRS feed

  • Question

  • I'm realy impressed. Even data conflict in multiuser environments are captured by LS by prsenting a UI and the diferences between client and server.

    So far so good. But I have a strange issue. I'm just testing in a single user environment. I'm initializing some fields in the xxxx_BeforeDataInitialize() event on a new record. So far all OK.

    When I change some field a data conflict occurs, not an the field I changed, but on a timestamp field
    The timestamp field is registering the creation date (as a default getdate() in the database).
    It is on this field that LS complains about a data conflict between client and server. The two values ls propose are even the same.

    If I open an existing record and change a field, everything is fine.

    Any Idea?

    Thanks

    Thursday, September 9, 2010 10:47 AM

Answers

  • if you want to set defaults on your new entity record, use entity_Created() partial method. This method will execute everytime you create a new record of that entity. To get to that method, do the following:

    1. open your entity in entity designer
    2. from the command bar, drop down write code method and select xxx_Created method.
    3. write your code in the method.

    Just out of curiosity, how are you initializing the new record in the BeforeDataInitialize method? 

    HTH,
    Babar 

    • Marked as answer by Bart.NET Thursday, September 16, 2010 9:30 AM
    Thursday, September 16, 2010 3:19 AM

All replies

  • Strange. Perhaps someone else monitoring this forum could provide an answer as to why that is happening.

    There are ways to get past it though. If this error is appearing when you save, you could override the save operation in code. This would cause LightSwitch to throw a ConcurrencyException. You coud catch the exception, determine of the property value and the server property value are the same, and then, when you are confident that values are the same, set a property that specifies that the client should win in the conflict. 

    You can find an example of overriding the Save button of a screen here - http://msdn.microsoft.com/en-us/library/ff851960.aspx. You can find a basic example of handling a ConcurrencyException in this topic - http://msdn.microsoft.com/en-us/library/ff851990.aspx. Note that this example does not show the comparison of the entity's property value with the server's version of the entity's property value. To accomplish that part, you would use the ConflictingProperties propery of the EntityConflict object. Then you can get to server and client property values and do your comparison.

    This would keep the annoying conflict resolution screen from appearing for something that shouldn't matter, but ultimately it would be better to know why the conflict message is proposing two identical values. I would love to know. Anyone?

     


    Norm Estabrook
    Thursday, September 9, 2010 6:36 PM
  • if you want to set defaults on your new entity record, use entity_Created() partial method. This method will execute everytime you create a new record of that entity. To get to that method, do the following:

    1. open your entity in entity designer
    2. from the command bar, drop down write code method and select xxx_Created method.
    3. write your code in the method.

    Just out of curiosity, how are you initializing the new record in the BeforeDataInitialize method? 

    HTH,
    Babar 

    • Marked as answer by Bart.NET Thursday, September 16, 2010 9:30 AM
    Thursday, September 16, 2010 3:19 AM
  • I think you should be setting fields on the record in the xxxx_Created event, not the xxxx_BeforeDateInitialize event. Have you tried that?
    If you believe that I've answered your question, please remember to mark it as answered.

    MicroApplications, Inc. -- Information Systems Integration and Custom Software Development
    Thursday, September 16, 2010 3:56 AM
  • Hi babar,

    It was a bad design. I've already changed it.
    The xxx_Created() was indeed the right way.

    I don't have to old code anymore. Sory for that

    Bart

    Thursday, September 16, 2010 9:30 AM