Problem getting Concurrency check to work

Posts   
 
    
Markiemac
User
Posts: 132
Joined: 25-Apr-2006
# Posted on: 21-Jan-2008 23:06:03   

Hi, (Using Adapter 2.5/VB/WinForm/SQL Server 2005)

I'm using a TimeStamp field called 'RowVer' for concurrency checks, and set the ConcurrencyPredicateFactory to use before the SaveEntity:

 sysParam.ConcurrencyPredicateFactoryToUse = New ConcurrencyPredicateFactory()
   adapter.SaveEntity(sysParam, True)

ConcurrencyPredicateFactory:

Imports SD.LLBLGen.Pro.ORMSupportClasses

Public Class ConcurrencyPredicateFactory
    Implements IConcurrencyPredicateFactory
    Public Function CreatePredicate(ByVal typeToCreate As ConcurrencyPredicateType, _
                                    ByVal containingEntity As Object) As IPredicateExpression _
                                    Implements IConcurrencyPredicateFactory.CreatePredicate
        Dim concurrencyPredicate As IPredicateExpression = New PredicateExpression()
        Dim entity As EntityBase2 = DirectCast(containingEntity, EntityBase2)
        If entity.Fields("RowVer") IsNot Nothing AndAlso typeToCreate = ConcurrencyPredicateType.Save Then
            concurrencyPredicate.Add(New FieldCompareValuePredicate(entity.Fields("RowVer"), Nothing, ComparisonOperator.Equal))
        End If
        Return concurrencyPredicate
    End Function
End Class

before saving the entity I update the row in Management Studio, but this is not detected by the ConcurrencyPredicateFactory. Can anyone see what I've missed?

Thanks

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 22-Jan-2008 02:11:40   

Hi Mark,

Markiemac wrote:


If entity.Fields("RowVer") IsNot Nothing AndAlso typeToCreate = ConcurrencyPredicateType.Save Then
     concurrencyPredicate.Add(New FieldCompareValuePredicate(entity.Fields("RowVer"), Nothing, ComparisonOperator.Equal))
       End If

I don't understand your predicate, Do you want that the Save action will only succeed if the TimeStamp remains the same? Shouldn't be:


concurrencyPredicate.Add(SysParamFields.RowVer = entity.Fields("RowVer").DbValue)
...
David Elizondo | LLBLGen Support Team
Markiemac
User
Posts: 132
Joined: 25-Apr-2006
# Posted on: 22-Jan-2008 11:06:21   

Hi David,

I don't understand your predicate, Do you want that the Save action will only succeed if the TimeStamp remains the same? Shouldn't be:


concurrencyPredicate.Add(SysParamFields.RowVer = entity.Fields("RowVer").DbValue)
...

That is what I want, but the above line hard codes SysParamFields. I thought that it was possible to create just one ConcurrencyPredicteFactory and use it when required. If so, how do I implement your code for all entities that will use this function?

ie. How do I modify the following to ensure the Save action only succeeds if TimeStamp remains the same?

   concurrencyPredicate.Add(New FieldCompareValuePredicate(entity.Fields("RowVer"), Nothing, ComparisonOperator.Equal))

Hope I'm on the right track confused

Thanks

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 22-Jan-2008 11:25:35   

A user has posted a Generic Concurrency Predicate implementation in the following thread: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=8998

Markiemac
User
Posts: 132
Joined: 25-Apr-2006
# Posted on: 22-Jan-2008 11:27:50   

Hi Walaa,

I must have missed that one. I'll have a look at it now.

Thanks <EDIT>

Worked perfectly