CollectionState IDataServiceCollection.SaveState( DataServiceContext context, Dictionary <EntityDescriptor, Guid> entityDescriptorToId) { if (this.observer == null) { throw new InvalidOperationException(Strings.DataServiceCollection_OperationForTrackedOnly); } if (this.observer.Context != context) { throw new InvalidOperationException(Strings.DataServiceState_CollectionNotInContext); } var state = new CollectionState(); state.EntitySetName = this.entitySetName; state.EntityTypeName = typeof(T).AssemblyQualifiedName; state.RootCollection = this.rootCollection; state.DescriptorIds = new List <Guid>(this.Count); foreach (object entity in this) { EntityDescriptor entityDescriptor = context.GetEntityDescriptor(entity); Guid id = entityDescriptorToId[entityDescriptor]; state.DescriptorIds.Add(id); } return(state); }
/// <summary> /// Creates the ResponseInfo object. /// </summary> /// <returns>ResponseInfo object.</returns> protected override ResponseInfo CreateResponseInfo() { DataServiceContext context = (DataServiceContext)this.Source; ClientEdmModel model = context.Model; ClientTypeAnnotation type = model.GetClientTypeAnnotation(model.GetOrCreateEdmType(this.entity.GetType())); Debug.Assert(type.IsEntityType, "Must be entity type to be contained."); return(this.RequestInfo.GetDeserializationInfoForLoadProperty( null, context.GetEntityDescriptor(this.entity), type.GetProperty(this.propertyName, false))); }
/// <summary> /// loading a property from a response /// </summary> /// <returns>QueryOperationResponse instance containing information about the response.</returns> internal QueryOperationResponse LoadProperty() { MaterializeAtom results = null; DataServiceContext context = (DataServiceContext)this.Source; ClientEdmModel model = context.Model; ClientTypeAnnotation type = model.GetClientTypeAnnotation(model.GetOrCreateEdmType(this.entity.GetType())); Debug.Assert(type.IsEntityType, "must be entity type to be contained"); EntityDescriptor box = context.GetEntityDescriptor(this.entity); if (EntityStates.Added == box.State) { throw Error.InvalidOperation(Strings.Context_NoLoadWithInsertEnd); } ClientPropertyAnnotation property = type.GetProperty(this.propertyName, false); Type elementType = property.EntityCollectionItemType ?? property.NullablePropertyType; try { if (type.MediaDataMember == property) { results = this.ReadPropertyFromRawData(property); } else { results = this.ReadPropertyFromAtom(property); } return(this.GetResponseWithType(results, elementType)); } catch (InvalidOperationException ex) { QueryOperationResponse response = this.GetResponseWithType(results, elementType); if (response != null) { response.Error = ex; throw new DataServiceQueryException(Strings.DataServiceException_GeneralError, ex, response); } throw; } }
internal QueryOperationResponse LoadProperty() { MaterializeAtom results = null; QueryOperationResponse responseWithType; DataServiceContext source = (DataServiceContext)base.Source; ClientEdmModel model = ClientEdmModel.GetModel(source.MaxProtocolVersion); ClientTypeAnnotation clientTypeAnnotation = model.GetClientTypeAnnotation(model.GetOrCreateEdmType(this.entity.GetType())); EntityDescriptor entityDescriptor = source.GetEntityDescriptor(this.entity); if (EntityStates.Added == entityDescriptor.State) { throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Context_NoLoadWithInsertEnd); } ClientPropertyAnnotation property = clientTypeAnnotation.GetProperty(this.propertyName, false); Type elementType = property.EntityCollectionItemType ?? property.NullablePropertyType; try { if (clientTypeAnnotation.MediaDataMember == property) { results = this.ReadPropertyFromRawData(property); } else { results = this.ReadPropertyFromAtom(entityDescriptor, property); } responseWithType = base.GetResponseWithType(results, elementType); } catch (InvalidOperationException exception) { QueryOperationResponse response = base.GetResponseWithType(results, elementType); if (response != null) { response.Error = exception; throw new DataServiceQueryException(System.Data.Services.Client.Strings.DataServiceException_GeneralError, exception, response); } throw; } return(responseWithType); }