public IRelationshipBuilder <TParentBuilder> SetData(IToManyResourceLinkage toManyResourceLinkage) { if (toManyResourceLinkage == null || toManyResourceLinkage.HasValueCollection == false) { this.SetDataNullOrEmpty(); return(this); } var rel = this.Rel; var resourceType = this.ResourceType; var relationship = resourceType.GetRelationshipInfo(rel); var toCardinality = relationship.ToCardinality; var toClrType = relationship.ToClrType; var toResourceType = this.ServiceModel.GetResourceType(toClrType); switch (toCardinality) { case RelationshipCardinality.ToOne: { var clrResourceTypeName = resourceType.ClrType.Name; var detail = InfrastructureErrorStrings.DocumentBuildExceptionDetailBuildToManyRelationshipResourceLinkageCardinalityMismatch .FormatWith(clrResourceTypeName, rel); throw new DocumentBuildException(detail); } case RelationshipCardinality.ToMany: { var toApiResourceIdentifierCollection = toManyResourceLinkage.CreateApiResourceIdentifierCollection(toResourceType) .SafeToReadOnlyCollection(); foreach (var domReadWriteRelationship in this.DomReadWriteRelationshipCollection) { domReadWriteRelationship.SetDomDataCollection(toApiResourceIdentifierCollection, toClrType); } break; } default: { var detail = InfrastructureErrorStrings.InternalErrorExceptionDetailUnknownEnumerationValue .FormatWith(typeof(RelationshipCardinality).Name, toCardinality); throw new InternalErrorException(detail); } } return(this); }
internal void SetDataInternal(IToManyResourceLinkage toManyResourceLinkage) { if (toManyResourceLinkage == null || toManyResourceLinkage.HasValueCollection == false) { this.SetDataNullOrEmpty(); return; } var rel = this.Rel; var resourceType = this.ResourceType; var relationship = resourceType.GetRelationshipInfo(rel); var toCardinality = relationship.ToCardinality; var toClrType = relationship.ToClrType; var toResourceType = this.ServiceModel.GetResourceType(toClrType); switch (toCardinality) { case RelationshipCardinality.ToOne: { var clrResourceTypeName = resourceType.ClrType.Name; var detail = InfrastructureErrorStrings.DocumentBuildExceptionDetailBuildToManyRelationshipResourceLinkageCardinalityMismatch .FormatWith(clrResourceTypeName, rel); throw new DocumentBuildException(detail); } case RelationshipCardinality.ToMany: { // ReSharper disable once PossibleNullReferenceException var toApiResourceIdentifierCollection = toManyResourceLinkage.CreateApiResourceIdentifierCollection(toResourceType); this.DomReadWriteRelationship.SetDomDataCollection(toApiResourceIdentifierCollection, toClrType); } break; default: { var detail = InfrastructureErrorStrings.InternalErrorExceptionDetailUnknownEnumerationValue .FormatWith(typeof(RelationshipCardinality).Name, toCardinality); throw new InternalErrorException(detail); } } }