コード例 #1
0
        static public DataServiceState Save(DataServiceContext context, Dictionary <string, object> collections)
        {
            List <Type> knownTypes = GetKnownTypes(context);

            Dictionary <EntityDescriptor, Guid> entityDescriptorToId;
            ContextState contextState    = context.SaveState(out entityDescriptorToId);
            string       contextAsString = SerializeContextToString(contextState, knownTypes);

            var collectionsState = new Dictionary <string, CollectionState>();

            if (collections != null)
            {
                foreach (KeyValuePair <string, object> kvp in collections)
                {
                    IDataServiceCollection collection      = (IDataServiceCollection)kvp.Value;
                    CollectionState        collectionState = collection.SaveState(context, entityDescriptorToId);
                    collectionsState.Add(kvp.Key, collectionState);
                }
            }

            DataServiceState state = new DataServiceState()
            {
                CollectionsState = collectionsState,
                ContextAsString  = contextAsString,
                ContextTypeName  = context.GetType().AssemblyQualifiedName,
                KnownTypeNames   = knownTypes.Select(t => t.AssemblyQualifiedName).ToList()
            };

            return(state);
        }
コード例 #2
0
        static public DataServiceState Save(DataServiceContext context, Dictionary<string,object> collections)
        {
            List<Type> knownTypes = GetKnownTypes(context);

            Dictionary<EntityDescriptor, Guid> entityDescriptorToId;
            ContextState contextState = context.SaveState(out entityDescriptorToId);
            string contextAsString = SerializeContextToString(contextState, knownTypes);

            var collectionsState = new Dictionary<string, CollectionState>();
            if (collections != null)
            {
                foreach (KeyValuePair<string, object> kvp in collections)
                {
                    IDataServiceCollection collection = (IDataServiceCollection) kvp.Value;
                    CollectionState collectionState = collection.SaveState(context, entityDescriptorToId);                    
                    collectionsState.Add(kvp.Key, collectionState);
                }
            }

            DataServiceState state = new DataServiceState()
            {
                CollectionsState = collectionsState,
                ContextAsString = contextAsString,
                ContextTypeName = context.GetType().AssemblyQualifiedName,
                KnownTypeNames = knownTypes.Select(t => t.AssemblyQualifiedName).ToList()
            };

            return state;
        }