IConcurrencyPredicateFactory and IEntity2.GetConcurrencyPredicate()

Posts   
 
    
jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 07-Aug-2007 21:42:48   

do these need to be used in conjunction with one another, or is this an either/or scenario.

I'm trying to implement concurrency and this is what i have. I seems redundant to me to leave the object only to return for the predicate.

public partial class EquipmentStatusEntity
{
    protected override void OnInitialized()
    {
        base.OnInitialized();
        this.ConcurrencyPredicateFactoryToUse = new ConcurrencyPredicateFactory();
    }

    public override IPredicateExpression GetConcurrencyPredicate(ConcurrencyPredicateType predicateTypeToCreate)
    {
        return new PredicateExpression(EquipmentStatusFields.UpdatedOn == this.Fields[(int)EquipmentStatusFieldIndex.UpdatedOn].DbValue);
    }
}

public partial class ConcurrencyPredicateFactory : IConcurrencyPredicateFactory
{
    #region IConcurrencyPredicateFactory Members

    public IPredicateExpression CreatePredicate(ConcurrencyPredicateType predicateTypeToCreate, object containingEntity)
    {
        IEntity2 entity = (IEntity2)containingEntity;
        if (entity == null)
        {
            throw new ArgumentException(string.Format("{0} does not inherit {1}", containingEntity.GetType().FullName, typeof(IEntity2).FullName), "containingEntity");
        }
        return entity.GetConcurrencyPredicate(predicateTypeToCreate);
    }

    #endregion
}

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 08-Aug-2007 00:57:16   

You could as well follow the by-the-book approach (see: Generated code - Using the entity classes, Adapter | Concurrency control), what I mean is that you could write a [_PerEntity_]ConcurrencyFactory to do the concurrency logic per entity, and later write a include template to initialize each entity (see: Generated code - Adding your own code to the generated classes | Include templates)

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 08-Aug-2007 14:34:20   

yes, I could. however I don't need concurrency on every table. and if it's generic enough why build a factory for each class?

also why could I need the concurrency predicate factory if the object itself has a GetConcurrencyPredicate() function?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 08-Aug-2007 18:49:16   

LLBLGenPro offers various ways to implement ConcurrencyControl. For a complete clarification read LLBLGenProHelp - Using generated code - Adapter - Use entity classes - Concurrency control. Also read this very nice David Hayden's article: http://davidhayden.com/blog/dave/archive/2006/10/24/ConcurrencyTimestampLLBLGenPro.aspx

David Elizondo | LLBLGen Support Team