Ejemplo n.º 1
0
        /// <summary>
        /// Сохранить отложенно
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="parentId"></param>
        /// <param name="index"></param>
        /// <param name="init"></param>
        public void SetDef <T>(T entity, object parentId = null, string index = null, bool init = true)
            where T : class
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }
            index = BuildIndx(index);

            if (init)
            {
                InitEntity(entity, index);
            }

            var setKey = new SetKey()
            {
                Index = index,
                //ParentId = parentId?.ToString(),
                Type = typeof(T),
            };

            lock (_setQueue)
            {
                if (!_setQueue.TryGetValue(setKey, out HashSet <object> queue))
                {
                    _setQueue.Add(setKey, queue = new HashSet <object>());
                }
                if (queue.Add(entity))
                {
                    _setDefCount++;
                }
            }
        }
Ejemplo n.º 2
0
 protected bool Equals(SetKey other) => string.Equals(Index, other.Index) && Type == other.Type && string.Equals(ParentId, other.ParentId);