Ejemplo n.º 1
0
        private void InterceptSave(List <object> interceptedEntities)
        {
            List <IEntityEntry> modifiedAndNotIntercepted = GetModifiedEntities(contextBuilder.Context)
                                                            .Where(e => !interceptedEntities.Contains(e.Entity)).ToList();

            if (modifiedAndNotIntercepted.Count == 0)
            {
                return;
            }

            foreach (IEntityEntry entry in modifiedAndNotIntercepted)
            {
                object entity = entry.Entity;

                Type entityType = ObjectContext.GetObjectType(entity.GetType());
                IEnumerable <IEntityInterceptor> entityInterceptors = interceptorsResolver.GetEntityInterceptors(entityType);

                if (entry.State == EntityEntryState.Deleted)
                {
                    Intercept(globalInterceptors, entity, (i, e) => i.OnDelete(e, this));
                    Intercept(entityInterceptors, entity, (i, e) => i.OnDelete(e, this));
                }
                else
                {
                    Intercept(globalInterceptors, entity, (i, e) => i.OnSave(e, this));
                    Intercept(entityInterceptors, entity, (i, e) => i.OnSave(e, this));
                }

                interceptedEntities.AddIfNotExists(entity);
            }

            InterceptSave(interceptedEntities);
        }
Ejemplo n.º 2
0
        private void OnEntityLoaded(object sender, EntityLoadedEventHandlerArgs e)
        {
            InterceptLoad(globalInterceptors, e.Entity);

            Type entityType = ObjectContext.GetObjectType(e.Entity.GetType());
            IEnumerable <IEntityInterceptor> entityInterceptors = interceptorsResolver.GetEntityInterceptors(entityType);

            InterceptLoad(entityInterceptors, e.Entity);
        }
            private void InterceptSave(List <object> interceptedEntities)
            {
                IEnumerable <object> modifiedEntities = GetInterceptorModifiedEntities(context).Select(e => e.Entity).ToList();

                if (modifiedEntities.All(interceptedEntities.Contains))
                {
                    return;
                }

                foreach (object entity in modifiedEntities.Where(e => !interceptedEntities.Contains(e)))
                {
                    InterceptSave(this.globalInterceptors, entity);

                    Type entityType = ObjectContext.GetObjectType(entity.GetType());
                    IEnumerable <IEntityInterceptor> interceptors = interceptorsResolver.GetEntityInterceptors(entityType);

                    this.InterceptSave(interceptors, entity);
                    interceptedEntities.AddIfNotExists(entity);
                }

                InterceptSave(interceptedEntities);
            }