Exemplo n.º 1
0
        public void Add(KeyValuePair <TKey, TValue> item)
        {
            if (Contains(item))
            {
                throw new System.ArgumentException("An item with same key added");
            }
            var document = new DictionaryDocument <TKey, TValue>
            {
                Id     = DicId,
                Key    = item.Key,
                Values = item.Value
            };

            _service.Collection.InsertOne(document);
        }
Exemplo n.º 2
0
        public void Add(TKey key, TValue value)
        {
            if (ContainsKey(key))
            {
                throw new System.ArgumentException("An item with same key added");
            }
            var document = new DictionaryDocument <TKey, TValue>
            {
                Id     = DicId,
                Key    = key,
                Values = value
            };

            _service.Collection.InsertOne(document);
            _service.Collection.Indexes.CreateOne(Builders <DictionaryDocument <TKey, TValue> > .IndexKeys.Ascending(_ => _.Key));
        }
Exemplo n.º 3
0
        public TValue this[TKey key]
        {
            get
            {
                var filter = GetFilters(key);

                var data = _service.Collection.Find(filter).Single();
                return(data.Values);
            }

            set
            {
                var filter = GetFilters(key);

                var document = new DictionaryDocument <TKey, TValue>
                {
                    Id     = DicId,
                    Key    = key,
                    Values = value
                };
                var data = _service.Collection.FindOneAndReplace(filter, document);
            }
        }