DataServiceProvider.DSPMetadata.AddKeyProperty C# (CSharp) Method

AddKeyProperty() public method

Adds a key property to the specified resourceType.
public AddKeyProperty ( System.Data.Services.Providers.ResourceType resourceType, string name, Type propertyType ) : void
resourceType System.Data.Services.Providers.ResourceType The resource type to add the property to.
name string The name of the property to add.
propertyType System.Type The CLR type of the property to add. This can be only a primitive type.
return void
        public void AddKeyProperty(ResourceType resourceType, string name, Type propertyType)
        {
            this.AddPrimitiveProperty(resourceType, name, propertyType, true);
        }

Usage Example

コード例 #1
0
        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);
                }
            }
        }
All Usage Examples Of DataServiceProvider.DSPMetadata::AddKeyProperty