Exemple #1
0
        private SaveResult ProcessSaveResult(EntityManager entityManager, SaveOptions saveOptions, JNode jNode)
        {
            var kms         = jNode.GetArray <KeyMapping>("KeyMappings");
            var keyMappings = kms.Select(km => ToEntityKeys(km, entityManager.MetadataStore)).ToDictionary(tpl => tpl.Item1, tpl => tpl.Item2);

            using (entityManager.NewIsLoadingBlock(false)) {
                keyMappings.ForEach(km => {
                    var targetEntity = entityManager.GetEntityByKey(km.Key);
                    targetEntity.EntityAspect.SetDpValue(km.Key.EntityType.KeyProperties[0], km.Value.Values[0]);
                });

                var entityNodes = jNode.GetToken <JArray>("Entities");

                var serializer     = new JsonSerializer();
                var mappingContext = new MappingContext()
                {
                    EntityManager      = entityManager,
                    MergeStrategy      = MergeStrategy.OverwriteChanges,
                    LoadingOperation   = LoadingOperation.Save,
                    JsonResultsAdapter = saveOptions.DataService.JsonResultsAdapter
                };
                var jsonConverter = new JsonEntityConverter(mappingContext);
                serializer.Converters.Add(jsonConverter);
                // serializer.Converters.Add(new StringEnumConverter());
                // Don't use the result of the Deserialize call to get the list of entities
                // because it won't include entities added on the server.
                serializer.Deserialize <IEnumerable <IEntity> >(entityNodes.CreateReader());
                var allEntities = mappingContext.Entities;
                allEntities.ForEach(e => e.EntityAspect.AcceptChanges());
                return(new SaveResult(allEntities, keyMappings));
            }
        }