Example #1
0
        public static void Register(HttpConfiguration config)
        {
            var model2 = EdmxReader.Parse(XmlReader.Create("http://localhost:9091/odata/$metadata"));

            var model = new EdmModel();
            model.AddReferencedModel(model2);

            var reference = new EdmReference("http://localhost:9091/odata/$metadata");
            reference.AddInclude(new EdmInclude("Model2", "SampleService2.Models"));
            model.SetEdmReferences(new List<IEdmReference> { reference });

            var container = new EdmEntityContainer("NS1", "Default");
            var order = model2.FindDeclaredType("SampleService2.Models.Order") as IEdmEntityType;
            model2.SetAnnotationValue<ClrTypeAnnotation>(order, new ClrTypeAnnotation(typeof(Order)));
            container.AddEntitySet("Orders", order);
            model.AddElement(container);

            var product = new EdmEntityType("NS1", "Product");
            product.AddKeys(product.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
            product.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
            model.AddElement(product);

            config.MapODataServiceRoute("odata", "odata", model);
        }
Example #2
0
        private static void MutualReferenceByCodeDemo()
        {
            Console.WriteLine("MutualReferenceByCodeDemo");

            var subModel1 = new EdmModel();
            var complex1 = new EdmComplexType("NS1", "Complex1");
            subModel1.AddElement(complex1);
            var reference1 = new EdmReference("http://model2");
            reference1.AddInclude(new EdmInclude("Alias2", "NS2"));
            var references1 = new List<IEdmReference> { reference1 };
            subModel1.SetEdmReferences(references1);

            var subModel2 = new EdmModel();
            var complex2 = new EdmComplexType("NS2", "Complex2");
            subModel2.AddElement(complex2);
            var reference2 = new EdmReference("http://model1");
            reference2.AddInclude(new EdmInclude("Alias1", "NS1"));
            var references2 = new List<IEdmReference> { reference2 };
            subModel2.SetEdmReferences(references2);

            complex1.AddStructuralProperty("Prop", new EdmComplexTypeReference(complex2, true));
            complex2.AddStructuralProperty("Prop", new EdmComplexTypeReference(complex1, true));

            var mainModel = new EdmModel();
            var complex3 = new EdmComplexType("NS", "Complex3");
            mainModel.AddElement(complex3);
            complex3.AddStructuralProperty("Prop1", new EdmComplexTypeReference(complex1, true));
            complex3.AddStructuralProperty("Prop2", new EdmComplexTypeReference(complex2, true));
            var references3 = new List<IEdmReference> { reference1, reference2 };
            mainModel.SetEdmReferences(references3);

            ShowModel(mainModel);
            ShowModel(subModel1);
            ShowModel(subModel2);
        }