/// <summary> /// Extends value population to include stream data /// </summary> /// <param name="row">The row containing the data</param> /// <param name="instance">The structural instacne</param> protected override void PopulateInstanceFromRow(EntitySetDataRow row, QueryStructuralValue instance) { base.PopulateInstanceFromRow(row, instance); var rowWithStreams = row as EntitySetDataRowWithStreams; if (rowWithStreams != null) { foreach (var stream in rowWithStreams.Streams) { if (stream.IsEditLinkBasedOnConvention) { ExceptionUtilities.CheckObjectNotNull(this.LinkGenerator, "Cannot compute convention-based edit link without injected generator"); stream.EditLink = this.LinkGenerator.GenerateStreamEditLink(instance, stream.Name); // for the default stream, there must always be a self-link if (stream.Name == null && stream.SelfLink == null) { stream.SelfLink = stream.EditLink; } } instance.SetStreamValue(stream.Name, stream.ContentType, stream.ETag, stream.EditLink, stream.SelfLink, stream.Content); } } instance.MarkDynamicPropertyValues(); }
/// <summary> /// Copies entity container data. /// </summary> /// <param name="data">The entity container data to copy data to.</param> public void CopyTo(EntityContainerData data) { foreach (EntitySet entitySet in this.EntityContainer.EntitySets) { foreach (EntitySetDataRow sourceRow in this[entitySet].Rows) { EntitySetDataRow destinationRow = data[entitySet].AddNewRowOfType(sourceRow.EntityType); foreach (string path in sourceRow.PropertyPaths) { destinationRow[path] = sourceRow[path]; } } } foreach (AssociationSet associationSet in this.EntityContainer.AssociationSets) { foreach (AssociationSetDataRow sourceRow in this[associationSet].Rows) { AssociationSetDataRow destinationRow = data[associationSet].AddNewRow(); foreach (string roleName in sourceRow.RoleNames) { destinationRow[roleName] = sourceRow[roleName]; } } } }
private EntitySetDataRow AddNewRowOfTypeInternal(EntityType entityType) { var row = new EntitySetDataRow(this, entityType); this.Rows.Add(row); return(row); }
private void InternalImportFrom(EntityType entityType, object[] data) { var addedRows = new List <EntitySetDataRow>(); foreach (object item in data) { var row = new EntitySetDataRow(this, entityType); row.ImportFrom(item); // Add new row only if Import succeeded. addedRows.Add(row); } // Add rows when all of them are successfully imported. foreach (EntitySetDataRow row in addedRows) { this.Rows.Add(row); } }
private void ConsiderCandidateForRelationships(EntitySetDataRow row) { foreach (RelationshipSelector rs in this.relationshipSelectors) { rs.ConsiderCandidate(row.Parent.EntitySet, row.EntityType, row.Key); } }
private EntitySetDataRow AddNewRowOfTypeInternal(EntityType entityType) { var row = new EntitySetDataRow(this, entityType); this.Rows.Add(row); return row; }
private void InternalImportFrom(EntityType entityType, object[] data) { var addedRows = new List<EntitySetDataRow>(); foreach (object item in data) { var row = new EntitySetDataRow(this, entityType); row.ImportFrom(item); // Add new row only if Import succeeded. addedRows.Add(row); } // Add rows when all of them are successfully imported. foreach (EntitySetDataRow row in addedRows) { this.Rows.Add(row); } }
private bool TryGetConstraints(EntitySetDataRow row, MemberProperty property, out List<PropertyConstraint> constraints) { constraints = null; List<PropertyWithConstraints> propertiesWithConstraints; if (this.entitySetToConstraintsMap.TryGetValue(row.Parent.EntitySet, out propertiesWithConstraints)) { constraints = propertiesWithConstraints .Where(p => p.Property == property) .Select(p => p.GetConstraints(row.EntityType)).SingleOrDefault(); if (constraints != null && constraints.Count == 0) { constraints = null; } } return constraints != null; }
private object ResolvePropertyValue(EntitySetDataRow row, MemberProperty property, List<PropertyConstraint> constraints) { if (this.resolved.Any(kv => kv.Key == row && kv.Value == property)) { return row[property.Name]; } KeyValuePair<EntitySetDataRow, MemberProperty> sameItem = this.visited.Where(kv => kv.Key == row && kv.Value == property).SingleOrDefault(); if (sameItem.Key != null) { int indexCycleStartsWith = this.visited.IndexOf(sameItem); List<object> values = this.visited.Where((kv, i) => i >= indexCycleStartsWith).Select(kv => kv.Key[kv.Value.Name]).Distinct(ValueComparer.Instance).ToList(); if (values.Count > 1) { throw new TaupoInvalidOperationException("Referential constraint cycle detected: " + GetReferentialConstraintCycleDescription(this.visited, indexCycleStartsWith)); } return values[0]; } var candidates = new List<object>(); foreach (PropertyConstraint constraint in constraints) { object candidate; if (this.ResolveConstraintValue(row, property, constraint, out candidate)) { candidates.Add(candidate); } } if (candidates.Distinct(ValueComparer.Instance).Count() > 1) { throw new TaupoInvalidOperationException("Overlapping foreign keys with conflicting values detected: " + GetOverlappingForeignKeyDescription(constraints)); } object value; if (candidates.Count > 0) { value = candidates[0]; if (!ValueComparer.Instance.Equals(value, row[property.Name])) { row[property.Name] = value; } } else { value = row[property.Name]; } this.resolved.Add(new KeyValuePair<EntitySetDataRow, MemberProperty>(row, property)); return value; }
private void ResolveConstraints(EntitySetDataRow row, PropertyWithConstraints propertyWithConstraints) { List<PropertyConstraint> constraints = propertyWithConstraints.GetConstraints(row.EntityType); if (constraints.Count > 0) { this.ResolvePropertyValue(row, propertyWithConstraints.Property, constraints); } }
private bool ResolveConstraintValue(EntitySetDataRow dependentRow, MemberProperty property, PropertyConstraint constraint, out object value) { value = null; List<AssociationSetDataRow> associationRows = this.data[constraint.AssociationSet].Rows.Where( r => ReferenceEquals(r.GetRoleKey(constraint.DependentRoleName), dependentRow.Key)).ToList(); if (associationRows.Count == 0) { return false; } if (associationRows.Count > 1) { throw new TaupoInvalidOperationException(string.Format( CultureInfo.InvariantCulture, "Multiplicity constraint violated: the association set '{0}' has multiple rows with the same role key for the dependent role '{1}'.", constraint.AssociationSet.Name, constraint.DependentRoleName)); } EntityDataKey principalKey = associationRows[0].GetRoleKey(constraint.PrincipalRoleName); EntitySetDataRow principalRow = this.data[constraint.PrincipalEntitySet].Rows.Where(r => ReferenceEquals(r.Key, principalKey)).SingleOrDefault(); if (principalRow != null) { List<PropertyConstraint> constraints; if (this.TryGetConstraints(principalRow, constraint.PrincipalProperty, out constraints)) { var item = new KeyValuePair<EntitySetDataRow, MemberProperty>(dependentRow, property); this.visited.Add(item); value = this.ResolvePropertyValue(principalRow, constraint.PrincipalProperty, constraints); this.visited.Remove(item); } else { value = principalRow[constraint.PrincipalProperty.Name]; } } else if (constraint.PrincipalProperty.IsPrimaryKey) { value = principalKey[constraint.PrincipalProperty.Name]; } return true; }