DataServiceProvider.DSPMetadata.AddReferenceProperty C# (CSharp) Method

AddReferenceProperty() private method

Helper method to add a reference property.
private AddReferenceProperty ( System.Data.Services.Providers.ResourceType resourceType, string name, System.Data.Services.Providers.ResourceSet targetResourceSet, bool resourceSetReference ) : void
resourceType System.Data.Services.Providers.ResourceType The resource type to add the property to.
name string The name of the property to add.
targetResourceSet System.Data.Services.Providers.ResourceSet The resource set the resource reference property points to.
resourceSetReference bool true if the property should be a resource set reference, false if it should be resource reference.
return void
        private void AddReferenceProperty(ResourceType resourceType, string name, ResourceSet targetResourceSet, bool resourceSetReference)
        {
            var property = new ResourceProperty(
                name,
                resourceSetReference ? ResourcePropertyKind.ResourceSetReference : ResourcePropertyKind.ResourceReference,
                targetResourceSet.ResourceType);
            property.CanReflectOnInstanceTypeProperty = false;
            resourceType.AddProperty(property);

            // We don't support type inheritance so the property can only point to the base resource type of the target resource set
            // We also don't support MEST, that is having two resource sets with the same resource type, so we can determine
            //   the resource set from the resource type. That also means that the property can never point to different resource sets
            //   so we can precreate the ResourceAssociationSet for this property right here as we have all the information.
            property.CustomState = new ResourcePropertyAnnotation()
            {
                ResourceAssociationSet = new ResourceAssociationSet(
                    resourceType.Name + "_" + name + "_" + targetResourceSet.Name,
                    new ResourceAssociationSetEnd(resourceType.GetAnnotation().ResourceSet, resourceType, property),
                    new ResourceAssociationSetEnd(targetResourceSet, targetResourceSet.ResourceType, null))
            };
        }