BeforeSaveEntity() protected method

The method is called for each entity to be saved before the save occurs. If this method returns 'false' then the entity will be excluded from the save. The base implementation returns the result of BeforeSaveEntityDelegate, or 'true' if BeforeSaveEntityDelegate is null.
protected BeforeSaveEntity ( EntityInfo entityInfo ) : bool
entityInfo EntityInfo
return bool
示例#1
0
 public void BeforeSave()
 {
     SaveMap = new Dictionary <Type, List <EntityInfo> >();
     EntitiesWithAutoGeneratedKeys = new List <EntityInfo>();
     EntityInfoGroups.ForEach(eg => {
         var entityInfos = eg.EntityInfos.Where(ei => ContextProvider.BeforeSaveEntity(ei)).ToList();
         EntitiesWithAutoGeneratedKeys.AddRange(entityInfos.Where(ei => ei.AutoGeneratedKey != null));
         SaveMap.Add(eg.EntityType, entityInfos);
     });
     SaveMap = ContextProvider.BeforeSaveEntities(SaveMap);
 }
 public void BeforeSave()
 {
     SaveMap = new Dictionary <Type, List <EntityInfo> >();
     EntityInfoGroups.ForEach(eg => {
         var entityInfos = eg.EntityInfos.Where(ei => ContextProvider.BeforeSaveEntity(ei)).ToList();
         SaveMap.Add(eg.EntityType, entityInfos);
     });
     SaveMap = ContextProvider.BeforeSaveEntities(SaveMap);
     EntitiesWithAutoGeneratedKeys = SaveMap
                                     .SelectMany(eiGrp => eiGrp.Value)
                                     .Where(ei => ei.AutoGeneratedKey != null && ei.EntityState != EntityState.Detached)
                                     .ToList();
 }
示例#3
0
        public async Task BeforeSaveAsync(CancellationToken cancellationToken)
        {
            SaveMap = new Dictionary <Type, List <EntityInfo> >();
            foreach (var eg in EntityInfoGroups)
            {
                var entityInfos = new List <EntityInfo>();
                foreach (var ei in eg.EntityInfos)
                {
                    if (ContextProvider.BeforeSaveEntity(ei) && await ContextProvider.BeforeSaveEntityAsync(ei, cancellationToken))
                    {
                        entityInfos.Add(ei);
                    }
                }
                SaveMap.Add(eg.EntityType, entityInfos);
            }
            SaveMap = await ContextProvider.BeforeSaveEntitiesAsync(ContextProvider.BeforeSaveEntities(SaveMap), cancellationToken);

            EntitiesWithAutoGeneratedKeys = SaveMap
                                            .SelectMany(eiGrp => eiGrp.Value)
                                            .Where(ei => ei.AutoGeneratedKey != null && ei.EntityState != EntityState.Detached)
                                            .ToList();
        }