Пример #1
0
        private string GetId(object entity)
        {
            string id;

            if (generateEntityIdOnTheClient.TryGetIdFromInstance(entity, out id))
            {
                id = generateEntityIdOnTheClient.GenerateDocumentKeyForStorage(entity);
            }
            else
            {
                id = generateEntityIdOnTheClient.GenerateDocumentKeyForStorage(entity);
                generateEntityIdOnTheClient.TrySetIdentity(entity, id);
            }
            return(id);
        }
Пример #2
0
        private string GetId(object entity)
        {
            string id;

            if (generateEntityIdOnTheClient.TryGetIdFromInstance(entity, out id) == false)
            {
                id = generateEntityIdOnTheClient.GenerateDocumentKeyForStorage(entity);
                generateEntityIdOnTheClient.TrySetIdentity(entity, id); //set Id property if it was null
            }
            return(id);
        }
Пример #3
0
        private void StoreInternal(object entity, Guid?etag, string id, bool forceConcurrencyCheck)
        {
            if (null == entity)
            {
                throw new ArgumentNullException("entity");
            }

            DocumentMetadata value;

            if (entitiesAndMetadata.TryGetValue(entity, out value))
            {
                value.ETag = etag ?? value.ETag;
                value.ForceConcurrencyCheck = forceConcurrencyCheck;
                return;
            }

            if (id == null)
            {
                if (GenerateDocumentKeysOnStore)
                {
                    id = GenerateEntityIdOnTheClient.GenerateDocumentKeyForStorage(entity);
                }
                else
                {
                    RememberEntityForDocumentKeyGeneration(entity);
                }
            }
            else
            {
                // Store it back into the Id field so the client has access to to it
                GenerateEntityIdOnTheClient.TrySetIdentity(entity, id);
            }

            // we make the check here even if we just generated the key
            // users can override the key generation behavior, and we need
            // to detect if they generate duplicates.
            AssertNoNonUniqueInstance(entity, id);

            var metadata = new RavenJObject();
            var tag      = documentStore.Conventions.GetTypeTagName(entity.GetType());

            if (tag != null)
            {
                metadata.Add(Constants.RavenEntityName, tag);
            }
            if (id != null)
            {
                knownMissingIds.Remove(id);
            }
            StoreEntityInUnitOfWork(id, entity, etag, metadata, forceConcurrencyCheck);
        }