I solved the problem.
There was a mistake at another place in my code.. Thanks again for your help. My code is below. Maybe others can use it.
It's a fully generic solution. The only thing you have to do in order to enable concurrency control for a specific entity is to add a timestamp field to the corresponding table in the database.
ConcurrencyPredicateFactory
[Serializable]
public class ConcurrencyPredicateFactory : IConcurrencyPredicateFactory {
private EntityField2 mTimestampField;
// constructor
public ConcurrencyPredicateFactory(IEntityField2 timestampField) {
mTimestampField = (EntityField2)timestampField;
}
public IPredicateExpression CreatePredicate(
ConcurrencyPredicateType predicateTypeToCreate,
object containingEntity) {
IPredicateExpression toReturn = new PredicateExpression();
EntityBase2 entity = (EntityBase2)containingEntity;
toReturn.Add(mTimestampField == entity.Fields["Timestamp"].DbValue);
return toReturn;
}
}
In Template Studio, add the following lines to the entityIncludeAdapter.template
protected override void OnBeforeEntitySave() {
base.OnBeforeEntitySave();
IEntityField2 timestampField = this.Fields["Timestamp"];
if (timestampField != null)
timestampField.CurrentValue = DateTime.Now;
}
In the same template as described above, look for the method InitClassEmpty(...) and add the following code to it:
IEntityField2 timestampField = this.Fields["Timestamp"];
if (timestampField != null)
ConcurrencyPredicateFactoryToUse = new ConcurrencyPredicateFactory(timestampField);
To enable concurrency control for an entity just add a Timestamp field to the corresponding table in the database (datatype Datetime).
If you have derived classes only add the Timestamp field to the root/base class.
That's all..