DataServiceProvider.DSPMetadata.AddComplexProperty C# (CSharp) Method

AddComplexProperty() public method

Adds a complex property to the specified resourceType.
public AddComplexProperty ( System.Data.Services.Providers.ResourceType resourceType, string name, System.Data.Services.Providers.ResourceType complexType ) : void
resourceType System.Data.Services.Providers.ResourceType The resource type to add the property to.
name string The name of the property to add.
complexType System.Data.Services.Providers.ResourceType Complex type to use for the property.
return void
        public void AddComplexProperty(ResourceType resourceType, string name, ResourceType complexType)
        {
            if (complexType.ResourceTypeKind != ResourceTypeKind.ComplexType)
            {
                throw new ArgumentException("The specified type for the complex property is not a complex type.");
            }

            var property = new ResourceProperty(name, ResourcePropertyKind.ComplexType, complexType);
            property.CanReflectOnInstanceTypeProperty = false;
            resourceType.AddProperty(property);
        }

Usage Example

        protected override void PopulateMetadata(DSPMetadata metadata, MongoContext context)
        {
            var itemsType = new ResourceType(typeof(Dictionary<string, object>),
                ResourceTypeKind.ComplexType, null, "Northwind", "Items", false);

            foreach (var collectionName in GetCollectionNames(context))
            {
                var collectionType = metadata.AddEntityType(collectionName);
                metadata.AddKeyProperty(collectionType, "Id", typeof(string));
                metadata.AddComplexProperty(collectionType, "Items", itemsType);
                metadata.AddResourceSet(collectionName, collectionType);
            }
        }