コード例 #1
0
        private static void AddNavigationBindings(IEntitySetConfiguration configuration, EdmEntitySet entitySet, EntitySetLinkBuilderAnnotation linkBuilder, ODataModelBuilder builder,
                                                  Dictionary <string, IEdmStructuredType> edmTypeMap, Dictionary <string, EdmEntitySet> edmEntitySetMap)
        {
            foreach (IEntityTypeConfiguration entity in builder.ThisAndBaseAndDerivedTypes(configuration.EntityType))
            {
                foreach (NavigationPropertyConfiguration navigation in entity.NavigationProperties)
                {
                    NavigationPropertyBinding binding = configuration.FindBinding(navigation);
                    if (binding != null)
                    {
                        EdmEntityType          edmEntityType         = edmTypeMap[entity.FullName] as EdmEntityType;
                        IEdmNavigationProperty edmNavigationProperty = edmEntityType.NavigationProperties().Single(np => np.Name == navigation.Name);

                        entitySet.AddNavigationTarget(edmNavigationProperty, edmEntitySetMap[binding.EntitySet.Name]);

                        Func <EntityInstanceContext, IEdmNavigationProperty, Uri> linkBuilderFunc = configuration.GetNavigationPropertyLink(navigation);
                        if (linkBuilderFunc != null)
                        {
                            linkBuilder.AddNavigationPropertyLinkBuilder(edmNavigationProperty, linkBuilderFunc);
                        }
                    }
                }
            }
        }
コード例 #2
0
        private static Dictionary <string, EdmEntitySet> AddEntitySets(this EdmModel model, ODataModelBuilder builder, EdmEntityContainer container, Dictionary <string, IEdmStructuredType> edmTypeMap)
        {
            IEnumerable <IEntitySetConfiguration> configurations = builder.EntitySets;

            // build the entitysets and their annotations
            IEnumerable <Tuple <EdmEntitySet, IEntitySetConfiguration> > entitySets = AddEntitySets(configurations, container, edmTypeMap);
            var entitySetAndAnnotations = entitySets.Select(e => new
            {
                EntitySet     = e.Item1,
                Configuration = e.Item2,
                Annotations   = new
                {
                    LinkBuilder = new EntitySetLinkBuilderAnnotation(e.Item2),
                    Url         = new EntitySetUrlAnnotation {
                        Url = e.Item2.GetUrl()
                    }
                }
            }).ToArray();

            // index the entitySets by name
            Dictionary <string, EdmEntitySet> edmEntitySetMap = entitySetAndAnnotations.ToDictionary(e => e.EntitySet.Name, e => e.EntitySet);

            // apply the annotations
            foreach (var iter in entitySetAndAnnotations)
            {
                EdmEntitySet entitySet = iter.EntitySet;
                model.SetAnnotationValue <EntitySetUrlAnnotation>(entitySet, iter.Annotations.Url);
                model.SetAnnotationValue <IEntitySetLinkBuilder>(entitySet, iter.Annotations.LinkBuilder);

                AddNavigationBindings(iter.Configuration, iter.EntitySet, iter.Annotations.LinkBuilder, builder, edmTypeMap, edmEntitySetMap);
            }
            return(edmEntitySetMap);
        }
コード例 #3
0
 public EntitySetLinkBuilderAnnotationTest()
 {
     _modelBuilder = new ODataModelBuilder();
     _entitySet    = _modelBuilder.AddEntitySet("Customers", _modelBuilder.AddEntity(typeof(Customer)));
 }
コード例 #4
0
 /// <summary>
 /// Create a new ActionConfiguration
 /// </summary>
 /// <param name="builder">The ODataModelBuilder to which this ActionConfiguration should be added.</param>
 /// <param name="name">The name of this ActionConfiguration.</param>
 public ActionConfiguration(ODataModelBuilder builder, string name)
 {
     Name         = name;
     ModelBuilder = builder;
     builder.AddProcedure(this);
 }
コード例 #5
0
 internal ComplexTypeConfiguration(ODataModelBuilder modelBuilder)
     : base(new ComplexTypeConfiguration(modelBuilder, typeof(TComplexType)))
 {
 }
コード例 #6
0
        // Returns the base types, this type and all the derived types of this type.
        public static IEnumerable <EntityTypeConfiguration> ThisAndBaseAndDerivedTypes(this ODataModelBuilder modelBuilder, EntityTypeConfiguration entity)
        {
            Contract.Assert(modelBuilder != null);
            Contract.Assert(entity != null);

            return(entity.BaseTypes()
                   .Concat(new[] { entity })
                   .Concat(modelBuilder.DerivedTypes(entity)));
        }