internal EntityStateFrame(object entity, object id, PersistenceOperationEnum persistenceOperation, string[] propertyNames, IType[] propertyTypes, object[] currentState, object[] previousState)
 {
     Entity = entity;
     Id     = id;
     PersistenceOperation = persistenceOperation;
     PropertyNames        = propertyNames;
     PropertyTypes        = propertyTypes;
     CurrentState         = currentState;
     PreviousState        = previousState;
 }
 internal EntityStateFrame(object entity, object id, PersistenceOperationEnum persistenceOperation, string[] propertyNames, IType[] propertyTypes, object[] currentState, object[] previousState)
 {
     Entity = entity;
     Id = id;
     PersistenceOperation = persistenceOperation;
     PropertyNames = propertyNames;
     PropertyTypes = propertyTypes;
     CurrentState = currentState;
     PreviousState = previousState;
 }
示例#3
0
        private void ValidateEntity(object o, object id, PersistenceOperationEnum persistenceOperation, IList <string> properties, IList <IType> types, IList <object> currentState, IList <object> previousState)
        {
            if (ReferenceEquals(_session, null))
            {
                return;
            }
            if (!ReferenceEquals(_session.Transaction, null) && _session.Transaction.WasRolledBack)
            {
                return;
            }
            var factoryName = _session.GetSessionImplementation().Factory.Settings.SessionFactoryName;
            var epc         = new EntityPersistenceContext {
                FactoryName = factoryName, Id = id
            };

            if (properties != null)
            {
                for (var i = 0; i < properties.Count; i++)
                {
                    if (currentState != null)
                    {
                        epc.CurrentState.Add(properties[i], currentState.ElementAtOrDefault(i));
                    }
                    if (types != null)
                    {
                        epc.Types.Add(properties[i], types.ElementAtOrDefault(i));
                    }
                }
            }
            switch (persistenceOperation)
            {
            case PersistenceOperationEnum.Adding:
                epc.IsBeingAdded = true;
                break;

            case PersistenceOperationEnum.Updating:
                epc.IsBeingModified = true;
                if (properties == null || previousState == null)
                {
                    break;
                }
                for (var i = 0; i < properties.Count; i++)
                {
                    epc.PreviousState.Add(properties[i], previousState.ElementAtOrDefault(i));
                }
                break;

            case PersistenceOperationEnum.Removing:
                epc.IsBeingRemoved = true;
                break;

            default:
                throw new ArgumentOutOfRangeException(persistenceOperation.ToString());
            }
            var validationResults = EntityValidator.DoMemberValidation(o, epc).ToList();

            if (validationResults.Count() == 0)
            {
                if (_validationResults.ContainsKey(o))
                {
                    //remove the validation errors from a previous flush
                    _validationResults.Remove(o);
                }
                return;
            }
            if (!_validationResults.ContainsKey(o))
            {
                //add the validation results for the entity
                _validationResults.Add(o, validationResults);
            }
            else
            {
                //replace the validation results for the entity
                _validationResults[o] = validationResults;
            }
        }
 private void ValidateEntity(object o, object id, PersistenceOperationEnum persistenceOperation, IList<string> properties, IList<IType> types, IList<object> currentState, IList<object> previousState)
 {
     if (ReferenceEquals(_session, null)) return;
     if (!ReferenceEquals(_session.Transaction, null) && _session.Transaction.WasRolledBack) return;
     var factoryName = _session.GetSessionImplementation().Factory.Settings.SessionFactoryName;
     var epc = new EntityPersistenceContext {FactoryName = factoryName, Id = id};
     if (properties != null)
     {
         for (var i = 0; i < properties.Count; i++)
         {
             if (currentState != null) epc.CurrentState.Add(properties[i], currentState.ElementAtOrDefault(i));
             if (types != null) epc.Types.Add(properties[i], types.ElementAtOrDefault(i));
         }    
     }
     switch (persistenceOperation)
     {
         case PersistenceOperationEnum.Adding:
             epc.IsBeingAdded = true;
             break;
         case PersistenceOperationEnum.Updating:
             epc.IsBeingModified = true;
             if (properties == null || previousState == null) break;
             for (var i = 0; i < properties.Count; i++ )
             {
                 epc.PreviousState.Add(properties[i], previousState.ElementAtOrDefault(i));    
             }
             break;
         case PersistenceOperationEnum.Removing:
             epc.IsBeingRemoved = true;
             break;
         default:
             throw new ArgumentOutOfRangeException(persistenceOperation.ToString());
     }
     var validationResults = EntityValidator.DoMemberValidation(o, epc).ToList();
     if (validationResults.Count() == 0)
     {
         if (_validationResults.ContainsKey(o))
         {
             //remove the validation errors from a previous flush
             _validationResults.Remove(o);
         }
         return;
     }
     if (!_validationResults.ContainsKey(o))
     {
         //add the validation results for the entity
         _validationResults.Add(o, validationResults);
     }
     else
     {
         //replace the validation results for the entity
         _validationResults[o] = validationResults;
     }
 }