/// <summary> /// Builds <see cref="IEdmType"/> and <see cref="IEdmProperty"/>'s from <paramref name="configurations"/> /// </summary> /// <param name="configurations">A collection of <see cref="StructuralTypeConfiguration"/>'s</param> /// <returns>The built dictionary of <see cref="IEdmStructuredType"/>'s indexed by their backing CLR type</returns> public static EdmTypeMap GetTypesAndProperties(IEnumerable <StructuralTypeConfiguration> configurations) { if (configurations == null) { throw Error.ArgumentNull("configurations"); } EdmTypeBuilder builder = new EdmTypeBuilder(configurations); return(new EdmTypeMap(builder.GetEdmTypes(), builder._directValueAnnotations)); }
/// <summary> /// Builds <see cref="IEdmType"/>'s from <paramref name="configurations"/> /// </summary> /// <param name="configurations">A collection of <see cref="IStructuralTypeConfiguration"/>'s</param> /// <returns>The built collection of <see cref="IEdmType"/></returns> public static IEnumerable <IEdmType> GetTypes(IEnumerable <IStructuralTypeConfiguration> configurations) { if (configurations == null) { throw Error.ArgumentNull("configurations"); } EdmTypeBuilder builder = new EdmTypeBuilder(configurations); return(builder.GetEdmTypes()); }
private static Dictionary <Type, IEdmStructuredType> AddTypes(this EdmModel model, IEnumerable <StructuralTypeConfiguration> types) { StructuralTypeConfiguration[] configTypes = types.ToArray(); // build types Dictionary <Type, IEdmStructuredType> edmTypes = EdmTypeBuilder.GetTypes(configTypes); // Add an annotate types model.AddTypes(edmTypes); model.AddClrTypeAnnotations(edmTypes); return(edmTypes); }
private static Dictionary <string, IEdmStructuredType> AddTypes(this EdmModel model, IEnumerable <IStructuralTypeConfiguration> types) { IStructuralTypeConfiguration[] configTypes = types.ToArray(); // build types IEdmStructuredType[] edmTypes = EdmTypeBuilder.GetTypes(configTypes).ToArray(); // index types Dictionary <string, IEdmStructuredType> edmTypeMap = edmTypes.ToDictionary(t => (t as IEdmSchemaType).FullName()); // Add an annotate types model.AddTypes(edmTypes); model.AddClrTypeAnnotations(GenerateEdmToClrMap(configTypes, edmTypeMap)); return(edmTypeMap); }
private static Dictionary <Type, IEdmStructuredType> AddTypes(this EdmModel model, IEnumerable <StructuralTypeConfiguration> types) { StructuralTypeConfiguration[] configTypes = types.ToArray(); // build types EdmTypeMap edmTypeMap = EdmTypeBuilder.GetTypesAndProperties(configTypes); Dictionary <Type, IEdmStructuredType> edmTypes = edmTypeMap.EdmTypes; // Add an annotate types model.AddTypes(edmTypes); model.AddClrTypeAnnotations(edmTypes); // Add direct value annotation model.AddDirectValueAnnotations(edmTypeMap.DirectValueAnnotations); return(edmTypes); }
/// <summary> /// Builds <see cref="IEdmType"/> and <see cref="IEdmProperty"/>'s from <paramref name="configurations"/> /// </summary> /// <param name="configurations">A collection of <see cref="StructuralTypeConfiguration"/>'s</param> /// <returns>The built dictionary of <see cref="StructuralTypeConfiguration"/>'s indexed by their backing CLR type, /// and dictionary of <see cref="StructuralTypeConfiguration"/>'s indexed by their backing CLR property info</returns> public static EdmTypeMap GetTypesAndProperties(IEnumerable<StructuralTypeConfiguration> configurations) { if (configurations == null) { throw Error.ArgumentNull("configurations"); } EdmTypeBuilder builder = new EdmTypeBuilder(configurations); return new EdmTypeMap(builder.GetEdmTypes(), builder._properties, builder._propertiesRestrictions); }
/// <summary> /// Builds <see cref="IEdmType"/>'s from <paramref name="configurations"/> /// </summary> /// <param name="configurations">A collection of <see cref="IStructuralTypeConfiguration"/>'s</param> /// <returns>The built collection of <see cref="IEdmType"/></returns> public static IEnumerable<IEdmStructuredType> GetTypes(IEnumerable<IStructuralTypeConfiguration> configurations) { if (configurations == null) { throw Error.ArgumentNull("configurations"); } EdmTypeBuilder builder = new EdmTypeBuilder(configurations); return builder.GetEdmTypes(); }
public static IEdmModel BuildEdmModel(string containerNamespace, string containerName, IEnumerable <IStructuralTypeConfiguration> entityTypeConfigurations, IEnumerable <IEntitySetConfiguration> entitySetConfigurations) { if (entityTypeConfigurations == null) { throw Error.ArgumentNull("entityTypeConfigurations"); } if (entitySetConfigurations == null) { throw Error.ArgumentNull("entitySetConfigurations"); } EdmModel model = new EdmModel(); Dictionary <string, IEdmStructuredType> types = EdmTypeBuilder.GetTypes(entityTypeConfigurations) .OfType <IEdmStructuredType>() .ToDictionary(t => t.ToString()); foreach (IEdmStructuredType type in types.Values) { if (type.TypeKind == EdmTypeKind.Complex) { model.AddElement(type as IEdmComplexType); } else if (type.TypeKind == EdmTypeKind.Entity) { model.AddElement(type as IEdmEntityType); } else { throw Error.InvalidOperation(SRResources.UnsupportedEntityTypeInModel); } } if (entitySetConfigurations.Any()) { EdmEntityContainer container = new EdmEntityContainer(containerNamespace, containerName); Dictionary <string, EdmEntitySet> edmEntitySetMap = new Dictionary <string, EdmEntitySet>(); foreach (IEntitySetConfiguration entitySet in entitySetConfigurations) { EdmEntitySet edmEntitySet = container.AddEntitySet(entitySet.Name, (IEdmEntityType)types[entitySet.EntityType.FullName]); EntitySetLinkBuilderAnnotation entitySetLinkBuilderAnnotation = new EntitySetLinkBuilderAnnotation(entitySet); model.SetEntitySetLinkBuilderAnnotation(edmEntitySet, entitySetLinkBuilderAnnotation); model.SetAnnotationValue <EntitySetUrlAnnotation>(edmEntitySet, new EntitySetUrlAnnotation { Url = entitySet.GetUrl() }); edmEntitySetMap.Add(edmEntitySet.Name, edmEntitySet); } foreach (IEntitySetConfiguration entitySet in entitySetConfigurations) { EdmEntitySet edmEntitySet = edmEntitySetMap[entitySet.Name]; EntitySetLinkBuilderAnnotation entitySetLinkBuilderAnnotation = model.GetEntitySetLinkBuilder(edmEntitySet) as EntitySetLinkBuilderAnnotation; foreach (NavigationPropertyConfiguration navigation in entitySet.EntityType.NavigationProperties) { NavigationPropertyBinding binding = entitySet.FindBinding(navigation); if (binding != null) { EdmEntityType edmEntityType = types[entitySet.EntityType.FullName] as EdmEntityType; IEdmNavigationProperty edmNavigationProperty = edmEntityType.NavigationProperties().Single(np => np.Name == navigation.Name); edmEntitySet.AddNavigationTarget(edmNavigationProperty, edmEntitySetMap[binding.EntitySet.Name]); entitySetLinkBuilderAnnotation.AddNavigationPropertyLinkBuilder(edmNavigationProperty, entitySet.GetNavigationPropertyLink(edmNavigationProperty.Name)); } } } model.AddElement(container); } return(model); }