internal void UpdateFromJNode(JNode jNode)
 {
     Check(EntityType.Name, jNode.Get <String>("entityTypeName"), "EntityTypeName");
     IsScalar        = jNode.Get <bool>("isScalar", true);
     AssociationName = jNode.Get <String>("associationName");
     _validators     = new ValidatorCollection(jNode.GetJNodeArray("validators"));
     SetFkNames(jNode.GetArray <String>("foreignKeyNames"));
     SetInvFkNames(jNode.GetArray <String>("invForeignKeyNames"));
     // custom
 }
        internal void UpdateFromJNode(JNode jNode, bool isFromServer)
        {
            var etName = MetadataStore.GetStructuralTypeNameFromJNode(jNode, "entityTypeName", isFromServer);

            Check(EntityType.Name, etName, "EntityTypeName");
            IsScalar        = jNode.Get <bool>("isScalar", true);
            AssociationName = jNode.Get <String>("associationName");
            _validators     = new ValidatorCollection(jNode.GetJNodeArray("validators"));
            SetFkNames(jNode.GetArray <String>(isFromServer ? "foreignKeyNamesOnServer" : "foreignKeyNames"));
            SetInvFkNames(jNode.GetArray <String>(isFromServer ? "invForeignKeyNamesOnServer" : "invForeignKeyNames"));
            // custom
        }
Example #3
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));
            }
        }
Example #4
0
        internal EntityKey(JNode jn, MetadataStore metadataStore)
        {
            var etName = jn.Get <String>("entityType");

            EntityType = metadataStore.GetEntityType(etName);
            ClrType    = EntityType.ClrType;
            // coerce the incoming data
            Values = jn.GetArray("values", EntityType.KeyProperties.Select(kp => kp.ClrType)).ToArray();
        }
Example #5
0
        internal SaveException(EntityManager em, JNode jn)
            : base()
        {
            _message = jn.Get <String>("ExceptionMessage") ?? "see EntityErrors";
            var entityErrors = jn.GetArray <EntityError>("Errors", "errors", "EntityErrors", "entityErrors");

            entityErrors  = entityErrors.Select(ee => ee.Resolve(em));
            _entityErrors = new SafeList <EntityError>(entityErrors);
            IsServerError = true;
        }