internal static void AddEntityType(DSPMetadata metadata, string entityTypeName, KeyValuePair <string, Type>[] properties, bool useComplexType, bool useOpenTypes) { var entityType = metadata.AddEntityType(entityTypeName, null, null, false); metadata.AddKeyProperty(entityType, "ID", typeof(int)); entityType.IsOpenType = useOpenTypes; if (!useOpenTypes) { Microsoft.OData.Service.Providers.ResourceType resourceTypeForProps; if (useComplexType) { string complexTypeName = GetComplexTypeName(entityTypeName); resourceTypeForProps = metadata.AddComplexType(complexTypeName, null, null, false); metadata.AddComplexProperty(entityType, "ComplexProperty", resourceTypeForProps); } else { resourceTypeForProps = entityType; } foreach (KeyValuePair <string, Type> property in properties) { metadata.AddPrimitiveProperty(resourceTypeForProps, property.Key, property.Value); } } string resourceSetName = GetResourceSetName(entityTypeName); metadata.AddResourceSet(resourceSetName, entityType); }
private static DSPMetadata GetModel(bool openType, bool namedStreams, Action <DSPMetadata> metadataModifier = null) { #region Model Definition // Navigation Collection Property: Client - Entity, Server - NonEntity DSPMetadata metadata = new DSPMetadata("ModelWithNonNullableProperties", "AstoriaUnitTests.Tests"); // Define people type having non-nullable properties var peopleType = metadata.AddEntityType("PeopleType", null, null, false); var officeType = metadata.AddComplexType("OfficeType", null, null, false); metadata.AddPrimitiveProperty(officeType, "Building", typeof(string)); metadata.AddPrimitiveProperty(officeType, "OfficeNumber", typeof(int)); peopleType.IsOpenType = openType; metadata.AddKeyProperty(peopleType, "ID", typeof(int)); if (!openType) { metadata.AddPrimitiveProperty(peopleType, "Name", typeof(string)); metadata.AddPrimitiveProperty(peopleType, "Body", typeof(byte[])); metadata.AddPrimitiveProperty(peopleType, "Age", typeof(Nullable <int>)); metadata.AddComplexProperty(peopleType, "Office", officeType); } var peopleSet = metadata.AddResourceSet("People", peopleType); if (metadataModifier != null) { metadataModifier(metadata); } metadata.SetReadOnly(); #endregion Model Definition return(metadata); }
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); } }