IConcurrencyPredicateFactory

Posts   
 
    
Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 07-May-2005 19:51:20   

Hi,

Here's my factory:


public class GenericFilterFactory : IConcurrencyPredicateFactory
    {
        public IPredicateExpression CreatePredicate(ConcurrencyPredicateType predicateTypeToCreate, object containingEntity)
        {
            IPredicateExpression toReturn = new PredicateExpression();
            EntityBase2 entity = (EntityBase2)containingEntity;

            switch (predicateTypeToCreate)
            {
                case ConcurrencyPredicateType.Delete:
                case ConcurrencyPredicateType.Save:
                    toReturn.Add(new FieldCompareValuePredicate(entity.Fields["ConcurrencyTimeStamp"], null, ComparisonOperator.Equal));
                    break;
            }
            return toReturn;
        }
    }

How do I create a new entity instance and set its 'ConcurrencyTimeStamp' property? Its says its readonly. I don't want to do the update of course but I do want to use the column's value in the where clause.

Cheers,

Ian.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39826
Joined: 17-Aug-2003
# Posted on: 08-May-2005 12:02:24   

The timestamp can't be set, because it's set by the database.

So on an entity which is loaded and should be saved based on a ConcurrencyPredicateFactory's created predicate, you use the timestamp column of that entity (as you do).

Could you elaborate a bit why you want to set a timestamp column in memory? The concurrencypredicatefactory isn't used for inserts. This is because inserts don't have a WHERE clause, as they insert a new row. ConcurrencyPredicateFactories are used for updates (and deletes), so you can define that the update only takes place if the row to update hasn't been altered for example. With an insert you don't have that.

Frans Bouma | Lead developer LLBLGen Pro
Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 08-May-2005 16:05:04   

When a user is editing an entity on a webpage, the instance used to populate the page isn't stored in session or anywhere else in memory.

So when the user posts back, I need to create a fresh instance, set it as not new and load up its data ready to be saved.

So I need to be able to set its timestamp column, the value of which, I'm storing in Viewstate.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39826
Joined: 17-Aug-2003
# Posted on: 09-May-2005 09:36:10   

Ok, in that case, use: entity.Fields[(int)TheEntityFieldIndex.TimestampColumn].ForcedCurrentValueWrite(timestampcolumn);

Frans Bouma | Lead developer LLBLGen Pro
Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 09-May-2005 15:05:32   

Thanks.