private void InternalAddNew(PackedObject packedObject) { if (packedObject.PrimaryKey.IsNull) { throw new NotSupportedException( $"Can not insert an object with null primary key: collection {CollectionSchema.CollectionName}"); } if (packedObject.CollectionName != CollectionSchema.CollectionName) { throw new InvalidOperationException( $"An object of type {packedObject.CollectionName} can not be stored in DataStore of type {CollectionSchema.CollectionName}"); } var primaryKey = packedObject.PrimaryKey; if (ReferenceEquals(primaryKey, null)) { throw new InvalidOperationException("can not store an object having a null primary key"); } DataByPrimaryKey.Add(primaryKey, packedObject); foreach (var metadata in CollectionSchema.UniqueKeyFields) { var value = packedObject.Values[metadata.Order]; var dictionaryToUse = _dataByUniqueKey[value.KeyName]; dictionaryToUse.Add(value, packedObject); } foreach (var index in _dataByIndexKey) { index.Value.Put(packedObject); } if (packedObject.FullText != null && packedObject.FullText.Length > 0) { _fullTextIndex.IndexDocument(packedObject); } }