Generic implementation of IConcurrencyPredicateFactory

Posts   
 
    
Robert.W
User
Posts: 79
Joined: 19-Jun-2007
# Posted on: 22-Feb-2010 12:33:39   

Hi,

Can anyone provide me with a generic implementation of IConcurrencyPredicateFactory that will use a field called Stamp. I'm trying to create one for quite some time but I'm unable to create a predicate without using MyEntityFields.Stamp and I would really like to have this by convention.

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 22-Feb-2010 15:43:19   

Please try any of the following:

                EntityBase2 entity = (EntityBase2)containingEntity;

                IPredicateExpression expression = new PredicateExpression();

                EntityField2 timestampField =
                    (EntityField2) EntityFieldFactory.Create(entity.GetType().Name, "Stamp");

                switch (predicateTypeToCreate)
                {
                    case ConcurrencyPredicateType.Save:
                        expression.Add(timestampField == entity.Fields["Stamp"].DbValue);
                        break;
                }

Or:

                EntityBase2 entity = (EntityBase2)containingEntity;

                IPredicateExpression expression = new PredicateExpression();

                switch (predicateTypeToCreate)
                {
                    case ConcurrencyPredicateType.Save:
                        expression.Add((EntityField2)entity.Fields["Version"] == entity.Fields["Version"].DbValue);
                        break;
                }

ref: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=15984

Robert.W
User
Posts: 79
Joined: 19-Jun-2007
# Posted on: 23-Feb-2010 08:57:28   

Thanks Walaa, that worked just fine. I believe that you internally use "2" as in EntityField2 for versioning - does that mean then some future version of LLBLGen will break this if you introduce EntityField3, EntityBase3 and I just regenerate my DAL without changing this code?

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 23-Feb-2010 09:06:17   

No. EntityField: For SelfServicing EntityField2: For Adapter

Robert.W
User
Posts: 79
Joined: 19-Jun-2007
# Posted on: 23-Feb-2010 09:27:48   

Thanks for clarifying that - thought it was versioning for ages now simple_smile . Again thanks for your help.