protected CreateEntityInfoFromJson ( dynamic jo, |
||
jo | dynamic | |
entityType | ||
Résultat |
protected internal EntityInfo CreateEntityInfoFromJson(dynamic jo, Type entityType) {
var entityInfo = CreateEntityInfo();
entityInfo.Entity = JsonSerializer.Deserialize(new JTokenReader(jo), entityType);
entityInfo.EntityState = (EntityState)Enum.Parse(typeof(EntityState), (String)jo.entityAspect.entityState);
entityInfo.ContextProvider = this;
entityInfo.UnmappedValuesMap = JsonToDictionary(jo.__unmapped);
entityInfo.OriginalValuesMap = JsonToDictionary(jo.entityAspect.originalValuesMap);
var autoGeneratedKey = jo.entityAspect.autoGeneratedKey;
if (entityInfo.EntityState == EntityState.Added && autoGeneratedKey != null) {
entityInfo.AutoGeneratedKey = new AutoGeneratedKey(entityInfo.Entity, autoGeneratedKey);
}
return entityInfo;
}
public SaveWorkState(ContextProvider contextProvider, JArray entitiesArray) { ContextProvider = contextProvider; var jObjects = entitiesArray.Select(jt => (dynamic)jt).ToList(); var groups = jObjects.GroupBy(jo => (String)jo.entityAspect.entityTypeName).ToList(); EntityInfoGroups = groups.Select(g => { var entityType = ContextProvider.LookupEntityType(g.Key); var entityInfos = g.Select(jo => ContextProvider.CreateEntityInfoFromJson(jo, entityType)).Cast <EntityInfo>().ToList(); return(new EntityGroup() { EntityType = entityType, EntityInfos = entityInfos }); }).ToList(); }