Beispiel #1
0
 public NavigationProperty(JNode jNode)
 {
     Name            = jNode.Get <String>("name");
     EntityTypeName  = jNode.Get <String>("entityTypeName");
     IsScalar        = jNode.Get <bool>("isScalar", true);
     AssociationName = jNode.Get <String>("associationName");
     // _validators.AddRange()
     _foreignKeyNames.AddRange(jNode.GetArray <String>("foreignKeyNames"));
     _invForeignKeyNames.AddRange(jNode.GetArray <String>("invForeignKeyNames"));
     // custom
 }
Beispiel #2
0
        private SaveResult ProcessSaveResult(EntityManager entityManager, string saveResultJson)
        {
            var jo = JObject.Parse(saveResultJson);

            var jn          = new JNode(jo);
            var kms         = jn.GetArray <KeyMapping>("KeyMappings");
            var keyMappings = kms.Select(km => ToEntityKeys(km)).ToDictionary(tpl => tpl.Item1, tpl => tpl.Item2);

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

                var prop = jo.Property("Entities");
                if (prop == null)
                {
                    return(null);
                }
                var entityNodes   = (JArray)prop.Value;
                var serializer    = new JsonSerializer();
                var jsonConverter = new JsonEntityConverter(entityManager, MergeStrategy.OverwriteChanges, NormalizeEntityTypeName);
                serializer.Converters.Add(jsonConverter);
                // 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 = jsonConverter.AllEntities;
                allEntities.ForEach(e => e.EntityAspect.AcceptChanges());
                return(new SaveResult(allEntities, keyMappings));
            }
        }
Beispiel #3
0
        internal EntityKey(JNode jn)
        {
            var etName = jn.Get <String>("entityType");

            EntityType = MetadataStore.Instance.GetEntityType(etName);
            ClrType    = EntityType.ClrType;
            // coerce the incoming data
            Values = jn.GetArray("values", EntityType.KeyProperties.Select(kp => kp.ClrType)).ToArray();
        }
Beispiel #4
0
        private void UpdateTempFks(IEntity targetEntity, JNode entityAspectNode, Dictionary <EntityKey, EntityKey> tempKeyMap)
        {
            var tempNavPropNames = entityAspectNode.GetArray <String>("tempNavPropNames");

            if (!tempNavPropNames.Any())
            {
                return;
            }
            var targetAspect = targetEntity.EntityAspect;
            var entityType   = targetAspect.EntityType;

            tempNavPropNames.ForEach(npName => {
                var np         = entityType.GetNavigationProperty(npName);
                var fkProp     = np.RelatedDataProperties[0];
                var oldFkValue = targetAspect.GetValue(fkProp);
                var oldFk      = new EntityKey(np.EntityType, oldFkValue);
                var newFk      = tempKeyMap[oldFk];
                targetAspect.SetValue(fkProp, newFk.Values[0]);
            });
        }