AddResourceSet() public method

Adds a resource set to the metadata definition.
public AddResourceSet ( string name, System.Data.Services.Providers.ResourceType entityType ) : System.Data.Services.Providers.ResourceSet
name string The name of the resource set to add.
entityType System.Data.Services.Providers.ResourceType The type of entities in the resource set.
return System.Data.Services.Providers.ResourceSet
        protected override void PopulateMetadata(DSPMetadata metadata, MongoContext context)
        {
            foreach (var collectionName in GetCollectionNames(context))
            {
                var collection = context.Database.GetCollection(collectionName);
                var document = collection.FindOne();
                if (document != null)
                {
                    var collectionType = metadata.AddEntityType(collectionName);

                    foreach (var element in document.Elements)
                    {
                        var elementType = GetElementType(context, element);
                        if (element.Name == "_id")
                        {
                            metadata.AddKeyProperty(collectionType, "ID", elementType);
                        }
                        else if (elementType == typeof(BsonDocument))
                        {
                            string referencedCollectionName = GetDocumentCollection(context, element.Value.AsBsonDocument).Name;
                            resourceReferences.Add(new Tuple<ResourceType, string, string>(collectionType, element.Name, referencedCollectionName));
                        }
                        else if (elementType == typeof(BsonArray))
                        {
                            var bsonArray = element.Value.AsBsonArray;
                            if (bsonArray != null && bsonArray.Count > 0)
                            {
                                string referencedCollectionName = GetDocumentCollection(context, bsonArray[0].AsBsonDocument).Name;
                                resourceSetReferences.Add(new Tuple<ResourceType, string, string>(collectionType, element.Name, referencedCollectionName));
                            }
                        }
                        else
                        {
                            metadata.AddPrimitiveProperty(collectionType, element.Name, elementType);
                        }
                    }
                    metadata.AddResourceSet(collectionName, collectionType);
                }
            }

            foreach (var reference in resourceReferences)
            {
                var referencedResourceSet = metadata.ResourceSets.Where(x => x.Name == reference.Item3).SingleOrDefault();
                if (referencedResourceSet != null)
                {
                    metadata.AddResourceSetReferenceProperty(reference.Item1, reference.Item2, referencedResourceSet);
                }
            }

            foreach (var reference in resourceSetReferences)
            {
                var referencedResourceSet = metadata.ResourceSets.Where(x => x.Name == reference.Item3).SingleOrDefault();
                if (referencedResourceSet != null)
                {
                    metadata.AddResourceSetReferenceProperty(reference.Item1, reference.Item2, referencedResourceSet);
                }
            }
        }
        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);
            }
        }