public void EdmSingletonBasicAttributeTest() { EdmSingleton singleton = new EdmSingleton(this.entityContainer, "VIP", customerType); singleton.Container.Should().Be(this.entityContainer); singleton.ContainerElementKind.Should().Be(EdmContainerElementKind.Singleton); singleton.EntityType().Should().Be(customerType); }
static InstanceAnnotationsReaderIntegrationTests() { EdmModel modelTmp = new EdmModel(); EntityType = new EdmEntityType("TestNamespace", "TestEntityType"); modelTmp.AddElement(EntityType); var keyProperty = new EdmStructuralProperty(EntityType, "ID", EdmCoreModel.Instance.GetInt32(false)); EntityType.AddKeys(new IEdmStructuralProperty[] { keyProperty }); EntityType.AddProperty(keyProperty); var resourceNavigationProperty = EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "ResourceNavigationProperty", Target = EntityType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne }); var resourceSetNavigationProperty = EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "ResourceSetNavigationProperty", Target = EntityType, TargetMultiplicity = EdmMultiplicity.Many }); var defaultContainer = new EdmEntityContainer("TestNamespace", "DefaultContainer_sub"); modelTmp.AddElement(defaultContainer); EntitySet = new EdmEntitySet(defaultContainer, "TestEntitySet", EntityType); EntitySet.AddNavigationTarget(resourceNavigationProperty, EntitySet); EntitySet.AddNavigationTarget(resourceSetNavigationProperty, EntitySet); defaultContainer.AddElement(EntitySet); Singleton = new EdmSingleton(defaultContainer, "TestSingleton", EntityType); Singleton.AddNavigationTarget(resourceNavigationProperty, EntitySet); Singleton.AddNavigationTarget(resourceSetNavigationProperty, EntitySet); defaultContainer.AddElement(Singleton); ComplexType = new EdmComplexType("TestNamespace", "TestComplexType"); ComplexType.AddProperty(new EdmStructuralProperty(ComplexType, "StringProperty", EdmCoreModel.Instance.GetString(false))); modelTmp.AddElement(ComplexType); Model = TestUtils.WrapReferencedModelsToMainModel("TestNamespace", "DefaultContainer", modelTmp); }
public void EdmSingletonAnnotationTests() { EdmModel model = new EdmModel(); EdmStructuralProperty customerProperty = new EdmStructuralProperty(customerType, "Name", EdmCoreModel.Instance.GetString(false)); customerType.AddProperty(customerProperty); model.AddElement(this.customerType); EdmSingleton vipCustomer = new EdmSingleton(this.entityContainer, "VIP", this.customerType); EdmTerm term = new EdmTerm(myNamespace, "SingletonAnnotation", EdmPrimitiveTypeKind.String); var annotation = new EdmAnnotation(vipCustomer, term, new EdmStringConstant("Singleton Annotation")); model.AddVocabularyAnnotation(annotation); var singletonAnnotation = vipCustomer.VocabularyAnnotations(model).Single(); Assert.Equal(vipCustomer, singletonAnnotation.Target); Assert.Equal("SingletonAnnotation", singletonAnnotation.Term.Name); singletonAnnotation = model.FindDeclaredVocabularyAnnotations(vipCustomer).Single(); Assert.Equal(vipCustomer, singletonAnnotation.Target); Assert.Equal("SingletonAnnotation", singletonAnnotation.Term.Name); EdmTerm propertyTerm = new EdmTerm(myNamespace, "SingletonPropertyAnnotation", EdmPrimitiveTypeKind.String); var propertyAnnotation = new EdmAnnotation(customerProperty, propertyTerm, new EdmStringConstant("Singleton Property Annotation")); model.AddVocabularyAnnotation(propertyAnnotation); var singletonPropertyAnnotation = customerProperty.VocabularyAnnotations(model).Single(); Assert.Equal(customerProperty, singletonPropertyAnnotation.Target); Assert.Equal("SingletonPropertyAnnotation", singletonPropertyAnnotation.Term.Name); }
public void EdmSingletonBasicNavigationPropertyBindingTest() { var internalOrderProperty = customerType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo(){Name = "InternalOrder", Target = this.orderType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne}); var externalOrderProperty = customerType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo(){Name = "ExternalOrders", Target = this.orderType, TargetMultiplicity = EdmMultiplicity.Many}); var customerProductProperty = customerType.AddBidirectionalNavigation( new EdmNavigationPropertyInfo() { Name = "Products", Target = this.productType, TargetMultiplicity = EdmMultiplicity.Many }, new EdmNavigationPropertyInfo() { Name = "Buyer", Target = this.customerType, TargetMultiplicity = EdmMultiplicity.One }); var orderSet = new EdmEntitySet(this.entityContainer, "Orders", this.orderType); var productSet = new EdmEntitySet(this.entityContainer, "Products", this.productType); var vipCustomer = new EdmSingleton(this.entityContainer, "VIP", this.customerType); vipCustomer.NavigationPropertyBindings.Should().HaveCount(0); vipCustomer.AddNavigationTarget(internalOrderProperty, orderSet); vipCustomer.AddNavigationTarget(externalOrderProperty, orderSet); vipCustomer.AddNavigationTarget(customerProductProperty, productSet); vipCustomer.NavigationPropertyBindings.Should().HaveCount(3) .And.Contain(m => m.NavigationProperty == internalOrderProperty && m.Target == orderSet) .And.Contain(m => m.NavigationProperty == externalOrderProperty && m.Target == orderSet) .And.Contain(m=>m.NavigationProperty == customerProductProperty && m.Target == productSet); vipCustomer.FindNavigationTarget(internalOrderProperty).Should().Be(orderSet); vipCustomer.FindNavigationTarget(externalOrderProperty).Should().Be(orderSet); vipCustomer.FindNavigationTarget(customerProductProperty).Should().Be(productSet); productSet.AddNavigationTarget(customerProductProperty.Partner, vipCustomer); productSet.FindNavigationTarget(customerProductProperty.Partner).Should().Be(vipCustomer); }
/// <summary> /// Creates and adds an singleton to this entity container. /// </summary> /// <param name="name">Name of the singleton.</param> /// <param name="entityType">The entity type of this singleton.</param> /// <returns>Created singleton.</returns> public virtual EdmSingleton AddSingleton(string name, IEdmEntityType entityType) { EdmSingleton singleton = new EdmSingleton(this, name, entityType); this.AddElement(singleton); return(singleton); }
public void TestEntityType() { var container = new EdmEntityContainer("NS", "C"); var entityType = new EdmEntityType("NS", "People"); var entitySet = new EdmEntitySet(container, "Peoples", entityType); Assert.AreEqual(entityType, entitySet.EntityType()); var singleton = new EdmSingleton(container, "Boss", entityType); Assert.AreEqual(entityType, singleton.EntityType()); }
public void GetEdmType_Returns_SingletonEntityType() { // Arrange Mock<IEdmEntityContainer> edmContainer = new Mock<IEdmEntityContainer>(); Mock<IEdmEntityType> entityType = new Mock<IEdmEntityType>(); IEdmSingleton edmSingleton = new EdmSingleton(edmContainer.Object, "singleton", entityType.Object); // Act SingletonPathSegment segment = new SingletonPathSegment(edmSingleton); // Assert Assert.Same(entityType.Object, segment.GetEdmType(previousEdmType: null)); }
static ODataAsynchronousReaderTests() { userModel = new EdmModel(); testType = new EdmEntityType("NS", "Test"); testType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32); userModel.AddElement(testType); var defaultContainer = new EdmEntityContainer("NS", "DefaultContainer"); userModel.AddElement(defaultContainer); singleton = new EdmSingleton(defaultContainer, "MySingleton", testType); defaultContainer.AddElement(singleton); }
static AsyncRoundtripJsonLightTests() { userModel = new EdmModel(); testType = new EdmEntityType("NS", "Test"); testType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32); testType.AddStructuralProperty("Dummy", EdmPrimitiveTypeKind.String); userModel.AddElement(testType); defaultContainer = new EdmEntityContainer("NS", "DefaultContainer"); userModel.AddElement(defaultContainer); singleton = new EdmSingleton(defaultContainer, "MySingleton", testType); defaultContainer.AddElement(singleton); }
public ODataJsonLightSingletonWriterTests() { referencedModel = new EdmModel(); this.webType = new EdmEntityType("NS", "Web"); this.webType.AddStructuralProperty("WebId", EdmPrimitiveTypeKind.Int32); this.webType.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); referencedModel.AddElement(this.webType); this.defaultContainer = new EdmEntityContainer("NS", "DefaultContainer_sub"); referencedModel.AddElement(defaultContainer); this.userModel = TestUtils.WrapReferencedModelsToMainModel("NS", "DefaultContainer", referencedModel); this.singleton = new EdmSingleton(defaultContainer, "MySingleton", this.webType); this.defaultContainer.AddElement(this.singleton); }
public void GetNavigationSourceLinkBuilder_After_SetNavigationSourceLinkBuilder_OnSingleton() { // Arrange IEdmModel model = new EdmModel(); EdmEntityContainer container = new EdmEntityContainer("NS", "Container"); EdmEntityType entityType = new EdmEntityType("NS", "Entity"); IEdmSingleton singleton = new EdmSingleton(container, "Singleton", entityType); NavigationSourceLinkBuilderAnnotation linkBuilder = new NavigationSourceLinkBuilderAnnotation(); // Act model.SetNavigationSourceLinkBuilder(singleton, linkBuilder); var result = model.GetNavigationSourceLinkBuilder(singleton); // Assert Assert.Same(linkBuilder, result); }
private ODataAsynchronousWriter TestInit() { this.userModel = new EdmModel(); testType = new EdmEntityType("NS", "Test"); testType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32); this.userModel.AddElement(testType); var defaultContainer = new EdmEntityContainer("NS", "DefaultContainer"); this.userModel.AddElement(defaultContainer); this.singleton = new EdmSingleton(defaultContainer, "MySingleton", this.testType); defaultContainer.AddElement(this.singleton); responseStream = new MemoryStream(); responseMessage = new InMemoryMessage { Stream = responseStream }; messageWriter = new ODataMessageWriter(responseMessage); return messageWriter.CreateODataAsynchronousWriter(); }
static InstanceAnnotationWriterIntegrationTests() { Model = new EdmModel(); EntityType = new EdmEntityType("TestNamespace", "TestEntityType"); Model.AddElement(EntityType); var keyProperty = new EdmStructuralProperty(EntityType, "ID", EdmCoreModel.Instance.GetInt32(false)); EntityType.AddKeys(new IEdmStructuralProperty[] { keyProperty }); EntityType.AddProperty(keyProperty); var resourceNavigationProperty = EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "ResourceNavigationProperty", Target = EntityType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne }); var resourceSetNavigationProperty = EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "ResourceSetNavigationProperty", Target = EntityType, TargetMultiplicity = EdmMultiplicity.Many }); var defaultContainer = new EdmEntityContainer("TestNamespace", "DefaultContainer"); Model.AddElement(defaultContainer); EntitySet = new EdmEntitySet(defaultContainer, "TestEntitySet", EntityType); EntitySet.AddNavigationTarget(resourceNavigationProperty, EntitySet); EntitySet.AddNavigationTarget(resourceSetNavigationProperty, EntitySet); defaultContainer.AddElement(EntitySet); Singleton = new EdmSingleton(defaultContainer, "TestSingleton", EntityType); Singleton.AddNavigationTarget(resourceNavigationProperty, EntitySet); Singleton.AddNavigationTarget(resourceSetNavigationProperty, EntitySet); defaultContainer.AddElement(Singleton); }
private void MediaEntrySetSetting() { referencedModel = new EdmModel(); this.webType = new EdmEntityType("NS", "Web", null, /*isAbstract*/false, /*isOpen*/false, /*hasStream*/true); referencedModel.AddElement(this.webType); this.defaultContainer = new EdmEntityContainer("NS", "DefaultContainer_sub"); referencedModel.AddElement(defaultContainer); this.userModel = TestUtils.WrapReferencedModelsToMainModel("NS", "DefaultContainer", referencedModel); this.singleton = new EdmSingleton(defaultContainer, "MySingleton", this.webType); this.defaultContainer.AddElement(this.singleton); }
public CraftModel() { model = new EdmModel(); var address = new EdmComplexType("NS", "Address"); model.AddElement(address); var mail = new EdmEntityType("NS", "Mail"); var mailId = mail.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32); mail.AddKeys(mailId); model.AddElement(mail); var person = new EdmEntityType("NS", "Person"); model.AddElement(person); var personId = person.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32); person.AddKeys(personId); person.AddStructuralProperty("Addr", new EdmComplexTypeReference(address, /*Nullable*/false)); MailBox = person.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { ContainsTarget = true, Name = "Mails", TargetMultiplicity = EdmMultiplicity.Many, Target = mail, }); var container = new EdmEntityContainer("NS", "DefaultContainer"); model.AddElement(container); MyLogin = container.AddSingleton("MyLogin", person); }
private void StreamTestSetting() { referencedModel = new EdmModel(); this.webType = new EdmEntityType("NS", "Web"); this.webType.AddStructuralProperty("Logo", EdmPrimitiveTypeKind.Stream); referencedModel.AddElement(this.webType); this.defaultContainer = new EdmEntityContainer("NS", "DefaultContainer_sub"); referencedModel.AddElement(defaultContainer); this.userModel = TestUtils.WrapReferencedModelsToMainModel("NS", "DefaultContainer", referencedModel); this.singleton = new EdmSingleton(defaultContainer, "MySingleton", this.webType); this.defaultContainer.AddElement(this.singleton); }
public static IEdmModel CreateTripPinServiceModel(string ns) { EdmModel model = new EdmModel(); var defaultContainer = new EdmEntityContainer(ns, "DefaultContainer"); model.AddElement(defaultContainer); var genderType = new EdmEnumType(ns, "PersonGender", isFlags: false); genderType.AddMember("Male", new EdmIntegerConstant(0)); genderType.AddMember("Female", new EdmIntegerConstant(1)); genderType.AddMember("Unknown", new EdmIntegerConstant(2)); model.AddElement(genderType); var cityType = new EdmComplexType(ns, "City"); cityType.AddProperty(new EdmStructuralProperty(cityType, "CountryRegion", EdmCoreModel.Instance.GetString(false))); cityType.AddProperty(new EdmStructuralProperty(cityType, "Name", EdmCoreModel.Instance.GetString(false))); cityType.AddProperty(new EdmStructuralProperty(cityType, "Region", EdmCoreModel.Instance.GetString(false))); model.AddElement(cityType); var locationType = new EdmComplexType(ns, "Location", null, false, true); locationType.AddProperty(new EdmStructuralProperty(locationType, "Address", EdmCoreModel.Instance.GetString(false))); locationType.AddProperty(new EdmStructuralProperty(locationType, "City", new EdmComplexTypeReference(cityType, false))); model.AddElement(locationType); var eventLocationType = new EdmComplexType(ns, "EventLocation", locationType, false, true); eventLocationType.AddProperty(new EdmStructuralProperty(eventLocationType, "BuildingInfo", EdmCoreModel.Instance.GetString(true))); model.AddElement(eventLocationType); var airportLocationType = new EdmComplexType(ns, "AirportLocation", locationType, false, true); airportLocationType.AddProperty(new EdmStructuralProperty(airportLocationType, "Loc", EdmCoreModel.Instance.GetSpatial(EdmPrimitiveTypeKind.GeographyPoint, false))); model.AddElement(airportLocationType); var photoType = new EdmEntityType(ns, "Photo", null, false, false, true); var photoIdProperty = new EdmStructuralProperty(photoType, "Id", EdmCoreModel.Instance.GetInt64(false)); photoType.AddProperty(photoIdProperty); photoType.AddKeys(photoIdProperty); photoType.AddProperty(new EdmStructuralProperty(photoType, "Name", EdmCoreModel.Instance.GetString(true))); model.AddElement(photoType); var photoSet = new EdmEntitySet(defaultContainer, "Photos", photoType); defaultContainer.AddElement(photoSet); var personType = new EdmEntityType(ns, "Person", null, false, /* isOpen */ true); var personIdProperty = new EdmStructuralProperty(personType, "UserName", EdmCoreModel.Instance.GetString(false)); personType.AddProperty(personIdProperty); personType.AddKeys(personIdProperty); personType.AddProperty(new EdmStructuralProperty(personType, "FirstName", EdmCoreModel.Instance.GetString(false))); personType.AddProperty(new EdmStructuralProperty(personType, "LastName", EdmCoreModel.Instance.GetString(false))); personType.AddProperty(new EdmStructuralProperty(personType, "Emails", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(true))))); personType.AddProperty(new EdmStructuralProperty(personType, "AddressInfo", new EdmCollectionTypeReference(new EdmCollectionType(new EdmComplexTypeReference(locationType, true))))); personType.AddProperty(new EdmStructuralProperty(personType, "Gender", new EdmEnumTypeReference(genderType, true))); personType.AddProperty(new EdmStructuralProperty(personType, "Concurrency", EdmCoreModel.Instance.GetInt64(false))); model.AddElement(personType); var personSet = new EdmEntitySet(defaultContainer, "People", personType); defaultContainer.AddElement(personSet); var airlineType = new EdmEntityType(ns, "Airline"); var airlineCodeProp = new EdmStructuralProperty(airlineType, "AirlineCode", EdmCoreModel.Instance.GetString(false)); airlineType.AddKeys(airlineCodeProp); airlineType.AddProperty(airlineCodeProp); airlineType.AddProperty(new EdmStructuralProperty(airlineType, "Name", EdmCoreModel.Instance.GetString(false))); model.AddElement(airlineType); var airlineSet = new EdmEntitySet(defaultContainer, "Airlines", airlineType); defaultContainer.AddElement(airlineSet); var airportType = new EdmEntityType(ns, "Airport"); var airportIdType = new EdmStructuralProperty(airportType, "IcaoCode", EdmCoreModel.Instance.GetString(false)); airportType.AddProperty(airportIdType); airportType.AddKeys(airportIdType); airportType.AddProperty(new EdmStructuralProperty(airportType, "Name", EdmCoreModel.Instance.GetString(false))); airportType.AddProperty(new EdmStructuralProperty(airportType, "IataCode", EdmCoreModel.Instance.GetString(false))); airportType.AddProperty(new EdmStructuralProperty(airportType, "Location", new EdmComplexTypeReference(airportLocationType, false))); model.AddElement(airportType); var airportSet = new EdmEntitySet(defaultContainer, "Airports", airportType); defaultContainer.AddElement(airportSet); var planItemType = new EdmEntityType(ns, "PlanItem"); var planItemIdType = new EdmStructuralProperty(planItemType, "PlanItemId", EdmCoreModel.Instance.GetInt32(false)); planItemType.AddProperty(planItemIdType); planItemType.AddKeys(planItemIdType); planItemType.AddProperty(new EdmStructuralProperty(planItemType, "ConfirmationCode", EdmCoreModel.Instance.GetString(true))); planItemType.AddProperty(new EdmStructuralProperty(planItemType, "StartsAt", EdmCoreModel.Instance.GetDateTimeOffset(true))); planItemType.AddProperty(new EdmStructuralProperty(planItemType, "EndsAt", EdmCoreModel.Instance.GetDateTimeOffset(true))); planItemType.AddProperty(new EdmStructuralProperty(planItemType, "Duration", EdmCoreModel.Instance.GetDuration(true))); model.AddElement(planItemType); var publicTransportationType = new EdmEntityType(ns, "PublicTransportation", planItemType); publicTransportationType.AddProperty(new EdmStructuralProperty(publicTransportationType, "SeatNumber", EdmCoreModel.Instance.GetString(true))); model.AddElement(publicTransportationType); var flightType = new EdmEntityType(ns, "Flight", publicTransportationType); var flightNumberType = new EdmStructuralProperty(flightType, "FlightNumber", EdmCoreModel.Instance.GetString(false)); flightType.AddProperty(flightNumberType); model.AddElement(flightType); var eventType = new EdmEntityType(ns, "Event", planItemType, false, true); eventType.AddProperty(new EdmStructuralProperty(eventType, "Description", EdmCoreModel.Instance.GetString(true))); eventType.AddProperty(new EdmStructuralProperty(eventType, "OccursAt", new EdmComplexTypeReference(eventLocationType, false))); model.AddElement(eventType); var tripType = new EdmEntityType(ns, "Trip"); var tripIdType = new EdmStructuralProperty(tripType, "TripId", EdmCoreModel.Instance.GetInt32(false)); tripType.AddProperty(tripIdType); tripType.AddKeys(tripIdType); tripType.AddProperty(new EdmStructuralProperty(tripType, "ShareId", EdmCoreModel.Instance.GetGuid(true))); tripType.AddProperty(new EdmStructuralProperty(tripType, "Description", EdmCoreModel.Instance.GetString(true))); tripType.AddProperty(new EdmStructuralProperty(tripType, "Name", EdmCoreModel.Instance.GetString(false))); tripType.AddProperty(new EdmStructuralProperty(tripType, "Budget", EdmCoreModel.Instance.GetSingle(false))); tripType.AddProperty(new EdmStructuralProperty(tripType, "StartsAt", EdmCoreModel.Instance.GetDateTimeOffset(false))); tripType.AddProperty(new EdmStructuralProperty(tripType, "EndsAt", EdmCoreModel.Instance.GetDateTimeOffset(false))); tripType.AddProperty(new EdmStructuralProperty(tripType, "Tags", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(false))))); model.AddElement(tripType); var friendsnNavigation = personType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Friends", Target = personType, TargetMultiplicity = EdmMultiplicity.Many }); var personTripNavigation = personType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Trips", Target = tripType, TargetMultiplicity = EdmMultiplicity.Many, ContainsTarget = true }); var personPhotoNavigation = personType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Photo", Target = photoType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne, }); var tripPhotosNavigation = tripType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Photos", Target = photoType, TargetMultiplicity = EdmMultiplicity.Many, }); var tripItemNavigation = tripType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "PlanItems", Target = planItemType, ContainsTarget = true, TargetMultiplicity = EdmMultiplicity.Many }); var flightFromAirportNavigation = flightType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "From", Target = airportType, TargetMultiplicity = EdmMultiplicity.One }); var flightToAirportNavigation = flightType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "To", Target = airportType, TargetMultiplicity = EdmMultiplicity.One }); var flightAirlineNavigation = flightType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Airline", Target = airlineType, TargetMultiplicity = EdmMultiplicity.One }); var me = new EdmSingleton(defaultContainer, "Me", personType); defaultContainer.AddElement(me); personSet.AddNavigationTarget(friendsnNavigation, personSet); me.AddNavigationTarget(friendsnNavigation, personSet); personSet.AddNavigationTarget(flightAirlineNavigation, airlineSet); me.AddNavigationTarget(flightAirlineNavigation, airlineSet); personSet.AddNavigationTarget(flightFromAirportNavigation, airportSet); me.AddNavigationTarget(flightFromAirportNavigation, airportSet); personSet.AddNavigationTarget(flightToAirportNavigation, airportSet); me.AddNavigationTarget(flightToAirportNavigation, airportSet); personSet.AddNavigationTarget(personPhotoNavigation, photoSet); me.AddNavigationTarget(personPhotoNavigation, photoSet); personSet.AddNavigationTarget(tripPhotosNavigation, photoSet); me.AddNavigationTarget(tripPhotosNavigation, photoSet); var getFavoriteAirlineFunction = new EdmFunction(ns, "GetFavoriteAirline", new EdmEntityTypeReference(airlineType, false), true, new EdmPathExpression("person/Trips/PlanItems/Microsoft.OData.SampleService.Models.TripPin.Flight/Airline"), true); getFavoriteAirlineFunction.AddParameter("person", new EdmEntityTypeReference(personType, false)); model.AddElement(getFavoriteAirlineFunction); var getInvolvedPeopleFunction = new EdmFunction(ns, "GetInvolvedPeople", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(personType, false))), true, null, true); getInvolvedPeopleFunction.AddParameter("trip", new EdmEntityTypeReference(tripType, false)); model.AddElement(getInvolvedPeopleFunction); var getFriendsTripsFunction = new EdmFunction(ns, "GetFriendsTrips", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(tripType, false))), true, new EdmPathExpression("person/Friends/Trips"), true); getFriendsTripsFunction.AddParameter("person", new EdmEntityTypeReference(personType, false)); getFriendsTripsFunction.AddParameter("userName", EdmCoreModel.Instance.GetString(false)); model.AddElement(getFriendsTripsFunction); var getNearestAirport = new EdmFunction(ns, "GetNearestAirport", new EdmEntityTypeReference(airportType, false), false, null, true); getNearestAirport.AddParameter("lat", EdmCoreModel.Instance.GetDouble(false)); getNearestAirport.AddParameter("lon", EdmCoreModel.Instance.GetDouble(false)); model.AddElement(getNearestAirport); var getNearestAirportFunctionImport = (IEdmFunctionImport)defaultContainer.AddFunctionImport("GetNearestAirport", getNearestAirport, new EdmEntitySetReferenceExpression(airportSet), true); var resetDataSourceAction = new EdmAction(ns, "ResetDataSource", null, false, null); model.AddElement(resetDataSourceAction); defaultContainer.AddActionImport(resetDataSourceAction); var shareTripAction = new EdmAction(ns, "ShareTrip", null, true, null); shareTripAction.AddParameter("person", new EdmEntityTypeReference(personType, false)); shareTripAction.AddParameter("userName", EdmCoreModel.Instance.GetString(false)); shareTripAction.AddParameter("tripId", EdmCoreModel.Instance.GetInt32(false)); model.AddElement(shareTripAction); model.SetDescriptionAnnotation(defaultContainer, "TripPin service is a sample service for OData V4."); model.SetOptimisticConcurrencyAnnotation(personSet, personType.StructuralProperties().Where(p => p.Name == "Concurrency")); // TODO: currently singleton does not support ETag feature // model.SetOptimisticConcurrencyAnnotation(me, personType.StructuralProperties().Where(p => p.Name == "Concurrency")); model.SetResourcePathCoreAnnotation(personSet, "People"); model.SetResourcePathCoreAnnotation(me, "Me"); model.SetResourcePathCoreAnnotation(airlineSet, "Airlines"); model.SetResourcePathCoreAnnotation(airportSet, "Airports"); model.SetResourcePathCoreAnnotation(photoSet, "Photos"); model.SetResourcePathCoreAnnotation(getNearestAirportFunctionImport, "Microsoft.OData.SampleService.Models.TripPin.GetNearestAirport"); model.SetDereferenceableIDsCoreAnnotation(defaultContainer, true); model.SetConventionalIDsCoreAnnotation(defaultContainer, true); model.SetPermissionsCoreAnnotation(personType.FindProperty("UserName"), CorePermission.Read); model.SetPermissionsCoreAnnotation(airlineType.FindProperty("AirlineCode"), CorePermission.Read); model.SetPermissionsCoreAnnotation(airportType.FindProperty("IcaoCode"), CorePermission.Read); model.SetPermissionsCoreAnnotation(planItemType.FindProperty("PlanItemId"), CorePermission.Read); model.SetPermissionsCoreAnnotation(tripType.FindProperty("TripId"), CorePermission.Read); model.SetPermissionsCoreAnnotation(photoType.FindProperty("Id"), CorePermission.Read); model.SetImmutableCoreAnnotation(airportType.FindProperty("IataCode"), true); model.SetComputedCoreAnnotation(personType.FindProperty("Concurrency"), true); model.SetAcceptableMediaTypesCoreAnnotation(photoType, new[] { "image/jpeg" }); model.SetConformanceLevelCapabilitiesAnnotation(defaultContainer, CapabilitiesConformanceLevelType.Advanced); model.SetSupportedFormatsCapabilitiesAnnotation(defaultContainer, new[] { "application/json;odata.metadata=full;IEEE754Compatible=false;odata.streaming=true", "application/json;odata.metadata=minimal;IEEE754Compatible=false;odata.streaming=true", "application/json;odata.metadata=none;IEEE754Compatible=false;odata.streaming=true" }); model.SetAsynchronousRequestsSupportedCapabilitiesAnnotation(defaultContainer, true); model.SetBatchContinueOnErrorSupportedCapabilitiesAnnotation(defaultContainer, false); model.SetNavigationRestrictionsCapabilitiesAnnotation(personSet, CapabilitiesNavigationType.None, new[] { new Tuple<IEdmNavigationProperty, CapabilitiesNavigationType>(friendsnNavigation, CapabilitiesNavigationType.Recursive) }); model.SetFilterFunctionsCapabilitiesAnnotation(defaultContainer, new[] { "contains", "endswith", "startswith", "length", "indexof", "substring", "tolower", "toupper", "trim", "concat", "year", "month", "day", "hour", "minute", "second", "round", "floor", "ceiling", "cast", "isof" }); model.SetSearchRestrictionsCapabilitiesAnnotation(personSet, true, CapabilitiesSearchExpressions.None); model.SetSearchRestrictionsCapabilitiesAnnotation(airlineSet, true, CapabilitiesSearchExpressions.None); model.SetSearchRestrictionsCapabilitiesAnnotation(airportSet, true, CapabilitiesSearchExpressions.None); model.SetSearchRestrictionsCapabilitiesAnnotation(photoSet, true, CapabilitiesSearchExpressions.None); model.SetInsertRestrictionsCapabilitiesAnnotation(personSet, true, new[] { personTripNavigation, friendsnNavigation }); model.SetInsertRestrictionsCapabilitiesAnnotation(airlineSet, true, null); model.SetInsertRestrictionsCapabilitiesAnnotation(airportSet, false, null); model.SetInsertRestrictionsCapabilitiesAnnotation(photoSet, true, null); // TODO: model.SetUpdateRestrictionsCapabilitiesAnnotation(); model.SetDeleteRestrictionsCapabilitiesAnnotation(airportSet, false, null); model.SetISOCurrencyMeasuresAnnotation(tripType.FindProperty("Budget"), "USD"); model.SetScaleMeasuresAnnotation(tripType.FindProperty("Budget"), 2); return model; }
public static IEdmModel CreateODataServiceModel(string ns) { EdmModel model = new EdmModel(); var defaultContainer = new EdmEntityContainer(ns, "InMemoryEntities"); model.AddElement(defaultContainer); #region ComplexType var addressType = new EdmComplexType(ns, "Address"); addressType.AddProperty(new EdmStructuralProperty(addressType, "Street", EdmCoreModel.Instance.GetString(false))); addressType.AddProperty(new EdmStructuralProperty(addressType, "City", EdmCoreModel.Instance.GetString(false))); addressType.AddProperty(new EdmStructuralProperty(addressType, "PostalCode", EdmCoreModel.Instance.GetString(false))); model.AddElement(addressType); var homeAddressType = new EdmComplexType(ns, "HomeAddress", addressType, false); homeAddressType.AddProperty(new EdmStructuralProperty(homeAddressType, "FamilyName", EdmCoreModel.Instance.GetString(true))); model.AddElement(homeAddressType); var companyAddressType = new EdmComplexType(ns, "CompanyAddress", addressType, false); companyAddressType.AddProperty(new EdmStructuralProperty(companyAddressType, "CompanyName", EdmCoreModel.Instance.GetString(false))); model.AddElement(companyAddressType); var cityInformationType = new EdmComplexType(ns, "CityInformation"); cityInformationType.AddProperty(new EdmStructuralProperty(cityInformationType, "CountryRegion", EdmCoreModel.Instance.GetString(false))); cityInformationType.AddProperty(new EdmStructuralProperty(cityInformationType, "IsCapital", EdmCoreModel.Instance.GetBoolean(false))); model.AddElement(cityInformationType); #endregion #region EnumType var accessLevelType = new EdmEnumType(ns, "AccessLevel", isFlags: true); accessLevelType.AddMember("None", new EdmIntegerConstant(0)); accessLevelType.AddMember("Read", new EdmIntegerConstant(1)); accessLevelType.AddMember("Write", new EdmIntegerConstant(2)); accessLevelType.AddMember("Execute", new EdmIntegerConstant(4)); accessLevelType.AddMember("ReadWrite", new EdmIntegerConstant(3)); model.AddElement(accessLevelType); var colorType = new EdmEnumType(ns, "Color", isFlags: false); colorType.AddMember("Red", new EdmIntegerConstant(1)); colorType.AddMember("Green", new EdmIntegerConstant(2)); colorType.AddMember("Blue", new EdmIntegerConstant(4)); model.AddElement(colorType); var companyCategory = new EdmEnumType(ns, "CompanyCategory", isFlags: false); companyCategory.AddMember("IT", new EdmIntegerConstant(0)); companyCategory.AddMember("Communication", new EdmIntegerConstant(1)); companyCategory.AddMember("Electronics", new EdmIntegerConstant(2)); companyCategory.AddMember("Others", new EdmIntegerConstant(4)); model.AddElement(companyCategory); #endregion #region Term model.AddElement(new EdmTerm(ns, "IsBoss", EdmCoreModel.Instance.GetBoolean(true), "Entity")); model.AddElement(new EdmTerm(ns, "AddressType", EdmCoreModel.Instance.GetString(true))); model.AddElement(new EdmTerm(ns, "CityInfo", new EdmComplexTypeReference(cityInformationType, false))); model.AddElement(new EdmTerm(ns, "DisplayName", EdmCoreModel.Instance.GetString(true))); #endregion var personType = new EdmEntityType(ns, "Person"); var personIdProperty = new EdmStructuralProperty(personType, "PersonID", EdmCoreModel.Instance.GetInt32(false)); personType.AddProperty(personIdProperty); personType.AddKeys(new IEdmStructuralProperty[] { personIdProperty }); personType.AddProperty(new EdmStructuralProperty(personType, "FirstName", EdmCoreModel.Instance.GetString(false))); personType.AddProperty(new EdmStructuralProperty(personType, "LastName", EdmCoreModel.Instance.GetString(false))); personType.AddProperty(new EdmStructuralProperty(personType, "MiddleName", EdmCoreModel.Instance.GetString(true))); personType.AddProperty(new EdmStructuralProperty(personType, "HomeAddress", new EdmComplexTypeReference(addressType, true))); personType.AddProperty(new EdmStructuralProperty(personType, "Home", EdmCoreModel.Instance.GetSpatial(EdmPrimitiveTypeKind.GeographyPoint, true))); personType.AddProperty(new EdmStructuralProperty(personType, "Numbers", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(false))))); personType.AddProperty(new EdmStructuralProperty(personType, "Emails", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(true))))); model.AddElement(personType); var personSet = new EdmEntitySet(defaultContainer, "People", personType); defaultContainer.AddElement(personSet); var boss = new EdmSingleton(defaultContainer, "Boss", personType); defaultContainer.AddElement(boss); var customerType = new EdmEntityType(ns, "Customer", personType); customerType.AddProperty(new EdmStructuralProperty(customerType, "City", EdmCoreModel.Instance.GetString(false))); customerType.AddProperty(new EdmStructuralProperty(customerType, "Birthday", EdmCoreModel.Instance.GetDateTimeOffset(false))); customerType.AddProperty(new EdmStructuralProperty(customerType, "TimeBetweenLastTwoOrders", EdmCoreModel.Instance.GetDuration(false))); model.AddElement(customerType); var customerSet = new EdmEntitySet(defaultContainer, "Customers", customerType); defaultContainer.AddElement(customerSet); EdmSingleton vipCustomer = new EdmSingleton(defaultContainer, "VipCustomer", customerType); defaultContainer.AddElement(vipCustomer); var employeeType = new EdmEntityType(ns, "Employee", personType); employeeType.AddProperty(new EdmStructuralProperty(employeeType, "DateHired", EdmCoreModel.Instance.GetDateTimeOffset(false))); employeeType.AddProperty(new EdmStructuralProperty(employeeType, "Office", EdmCoreModel.Instance.GetSpatial(EdmPrimitiveTypeKind.GeographyPoint, true))); model.AddElement(employeeType); var employeeSet = new EdmEntitySet(defaultContainer, "Employees", employeeType); defaultContainer.AddElement(employeeSet); var productType = new EdmEntityType(ns, "Product"); var productIdProperty = new EdmStructuralProperty(productType, "ProductID", EdmCoreModel.Instance.GetInt32(false)); productType.AddProperty(productIdProperty); productType.AddKeys(productIdProperty); productType.AddProperty(new EdmStructuralProperty(productType, "Name", EdmCoreModel.Instance.GetString(false))); productType.AddProperty(new EdmStructuralProperty(productType, "QuantityPerUnit", EdmCoreModel.Instance.GetString(false))); productType.AddProperty(new EdmStructuralProperty(productType, "UnitPrice", EdmCoreModel.Instance.GetSingle(false))); productType.AddProperty(new EdmStructuralProperty(productType, "QuantityInStock", EdmCoreModel.Instance.GetInt32(false))); productType.AddProperty(new EdmStructuralProperty(productType, "Discontinued", EdmCoreModel.Instance.GetBoolean(false))); productType.AddProperty(new EdmStructuralProperty(productType, "UserAccess", new EdmEnumTypeReference(accessLevelType, true))); productType.AddProperty(new EdmStructuralProperty(productType, "SkinColor", new EdmEnumTypeReference(colorType, true))); productType.AddProperty(new EdmStructuralProperty(productType, "CoverColors", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEnumTypeReference(colorType, false))))); model.AddElement(productType); var productSet = new EdmEntitySet(defaultContainer, "Products", productType); defaultContainer.AddElement(productSet); var productDetailType = new EdmEntityType(ns, "ProductDetail"); var productDetailIdProperty1 = new EdmStructuralProperty(productDetailType, "ProductID", EdmCoreModel.Instance.GetInt32(false)); var productDetailIdProperty2 = new EdmStructuralProperty(productDetailType, "ProductDetailID", EdmCoreModel.Instance.GetInt32(false)); productDetailType.AddProperty(productDetailIdProperty1); productDetailType.AddKeys(productDetailIdProperty1); productDetailType.AddProperty(productDetailIdProperty2); productDetailType.AddKeys(productDetailIdProperty2); productDetailType.AddProperty(new EdmStructuralProperty(productDetailType, "ProductName", EdmCoreModel.Instance.GetString(false))); productDetailType.AddProperty(new EdmStructuralProperty(productDetailType, "Description", EdmCoreModel.Instance.GetString(false))); model.AddElement(productDetailType); var productDetailSet = new EdmEntitySet(defaultContainer, "ProductDetails", productDetailType); defaultContainer.AddElement(productDetailSet); var productReviewType = new EdmEntityType(ns, "ProductReview"); var productReviewIdProperty1 = new EdmStructuralProperty(productReviewType, "ProductID", EdmCoreModel.Instance.GetInt32(false)); var productReviewIdProperty2 = new EdmStructuralProperty(productReviewType, "ProductDetailID", EdmCoreModel.Instance.GetInt32(false)); var productReviewIdProperty3 = new EdmStructuralProperty(productReviewType, "ReviewTitle", EdmCoreModel.Instance.GetString(false)); var productReviewIdProperty4 = new EdmStructuralProperty(productReviewType, "RevisionID", EdmCoreModel.Instance.GetInt32(false)); productReviewType.AddProperty(productReviewIdProperty1); productReviewType.AddKeys(productReviewIdProperty1); productReviewType.AddProperty(productReviewIdProperty2); productReviewType.AddKeys(productReviewIdProperty2); productReviewType.AddProperty(productReviewIdProperty3); productReviewType.AddKeys(productReviewIdProperty3); productReviewType.AddProperty(productReviewIdProperty4); productReviewType.AddKeys(productReviewIdProperty4); productReviewType.AddProperty(new EdmStructuralProperty(productReviewType, "Comment", EdmCoreModel.Instance.GetString(false))); productReviewType.AddProperty(new EdmStructuralProperty(productReviewType, "Author", EdmCoreModel.Instance.GetString(false))); model.AddElement(productReviewType); var productReviewSet = new EdmEntitySet(defaultContainer, "ProductReviews", productReviewType); defaultContainer.AddElement(productReviewSet); var abstractType = new EdmEntityType(ns, "AbstractEntity", null, true, false); model.AddElement(abstractType); var orderType = new EdmEntityType(ns, "Order", abstractType); var orderIdProperty = new EdmStructuralProperty(orderType, "OrderID", EdmCoreModel.Instance.GetInt32(false)); orderType.AddProperty(orderIdProperty); orderType.AddKeys(orderIdProperty); orderType.AddProperty(new EdmStructuralProperty(orderType, "OrderDate", EdmCoreModel.Instance.GetDateTimeOffset(false))); orderType.AddProperty(new EdmStructuralProperty(orderType, "ShelfLife", EdmCoreModel.Instance.GetDuration(true))); orderType.AddProperty(new EdmStructuralProperty(orderType, "OrderShelfLifes", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetDuration(true))))); orderType.AddProperty(new EdmStructuralProperty(orderType, "ShipDate", EdmCoreModel.Instance.GetDate(false))); orderType.AddProperty(new EdmStructuralProperty(orderType, "ShipTime", EdmCoreModel.Instance.GetTimeOfDay(false))); model.AddElement(orderType); var orderSet = new EdmEntitySet(defaultContainer, "Orders", orderType); defaultContainer.AddElement(orderSet); var orderDetailType = new EdmEntityType(ns, "OrderDetail", abstractType); var orderId = new EdmStructuralProperty(orderDetailType, "OrderID", EdmCoreModel.Instance.GetInt32(false)); orderDetailType.AddProperty(orderId); orderDetailType.AddKeys(orderId); var productId = new EdmStructuralProperty(orderDetailType, "ProductID", EdmCoreModel.Instance.GetInt32(false)); orderDetailType.AddProperty(productId); orderDetailType.AddKeys(productId); orderDetailType.AddProperty(new EdmStructuralProperty(orderDetailType, "OrderPlaced", EdmCoreModel.Instance.GetDateTimeOffset(false))); orderDetailType.AddProperty(new EdmStructuralProperty(orderDetailType, "Quantity", EdmCoreModel.Instance.GetInt32(false))); orderDetailType.AddProperty(new EdmStructuralProperty(orderDetailType, "UnitPrice", EdmCoreModel.Instance.GetSingle(false))); model.AddElement(orderDetailType); var orderDetailSet = new EdmEntitySet(defaultContainer, "OrderDetails", orderDetailType); defaultContainer.AddElement(orderDetailSet); var parentNavigation = personType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Parent", Target = personType, TargetMultiplicity = EdmMultiplicity.One }); var productOrderedNavigation = orderDetailType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "ProductOrdered", Target = productType, TargetMultiplicity = EdmMultiplicity.Many }); var associatedOrderNavigation = orderDetailType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "AssociatedOrder", Target = orderType, TargetMultiplicity = EdmMultiplicity.One }); var loggedInEmployeeNavigation = orderType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "LoggedInEmployee", Target = employeeType, TargetMultiplicity = EdmMultiplicity.One }); var customerForOrderNavigation = orderType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "CustomerForOrder", Target = customerType, TargetMultiplicity = EdmMultiplicity.One }); var orderDetailsNavigation = orderType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "OrderDetails", Target = orderDetailType, TargetMultiplicity = EdmMultiplicity.Many }); var ordersNavigation = customerType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Orders", Target = orderType, TargetMultiplicity = EdmMultiplicity.Many }); var productProductDetailNavigation = productType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Details", TargetMultiplicity = EdmMultiplicity.Many, Target = productDetailType, DependentProperties = new List<IEdmStructuralProperty>() { productIdProperty }, PrincipalProperties = new List<IEdmStructuralProperty>() { productDetailIdProperty1 } }); var productDetailProductNavigation = productDetailType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "RelatedProduct", Target = productType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne }); var productDetailProductReviewNavigation = productDetailType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Reviews", TargetMultiplicity = EdmMultiplicity.Many, Target = productReviewType, DependentProperties = new List<IEdmStructuralProperty>() { productDetailIdProperty1, productDetailIdProperty2, }, PrincipalProperties = new List<IEdmStructuralProperty>() { productReviewIdProperty1, productReviewIdProperty2 } }); model.SetCoreChangeTrackingAnnotation(orderSet, new EdmStructuralProperty[] { orderIdProperty }, new EdmNavigationProperty[] { orderDetailsNavigation }); ((EdmEntitySet)personSet).AddNavigationTarget(parentNavigation, personSet); ((EdmEntitySet)orderDetailSet).AddNavigationTarget(associatedOrderNavigation, orderSet); ((EdmEntitySet)orderDetailSet).AddNavigationTarget(productOrderedNavigation, productSet); ((EdmEntitySet)customerSet).AddNavigationTarget(ordersNavigation, orderSet); ((EdmEntitySet)customerSet).AddNavigationTarget(parentNavigation, personSet); ((EdmEntitySet)employeeSet).AddNavigationTarget(parentNavigation, personSet); ((EdmEntitySet)orderSet).AddNavigationTarget(loggedInEmployeeNavigation, employeeSet); ((EdmEntitySet)orderSet).AddNavigationTarget(customerForOrderNavigation, customerSet); ((EdmEntitySet)orderSet).AddNavigationTarget(orderDetailsNavigation, orderDetailSet); ((EdmEntitySet)productSet).AddNavigationTarget(productProductDetailNavigation, productDetailSet); ((EdmEntitySet)productDetailSet).AddNavigationTarget(productDetailProductNavigation, productSet); ((EdmEntitySet)productDetailSet).AddNavigationTarget(productDetailProductReviewNavigation, productReviewSet); #region Singleton var departmentType = new EdmEntityType(ns, "Department", null); var departmentId = new EdmStructuralProperty(departmentType, "DepartmentID", EdmCoreModel.Instance.GetInt32(false)); departmentType.AddProperty(departmentId); departmentType.AddKeys(departmentId); departmentType.AddProperty(new EdmStructuralProperty(departmentType, "Name", EdmCoreModel.Instance.GetString(false))); departmentType.AddProperty(new EdmStructuralProperty(departmentType, "DepartmentNO", EdmCoreModel.Instance.GetString(true))); model.AddElement(departmentType); EdmEntitySet departments = new EdmEntitySet(defaultContainer, "Departments", departmentType); defaultContainer.AddElement(departments); var companyType = new EdmEntityType(ns, "Company", /*baseType*/ null, /*isAbstract*/ false, /*isOpen*/ true); var companyId = new EdmStructuralProperty(companyType, "CompanyID", EdmCoreModel.Instance.GetInt32(false)); companyType.AddProperty(companyId); companyType.AddKeys(companyId); companyType.AddProperty(new EdmStructuralProperty(companyType, "CompanyCategory", new EdmEnumTypeReference(companyCategory, true))); companyType.AddProperty(new EdmStructuralProperty(companyType, "Revenue", EdmCoreModel.Instance.GetInt64(false))); companyType.AddProperty(new EdmStructuralProperty(companyType, "Name", EdmCoreModel.Instance.GetString(true))); companyType.AddProperty(new EdmStructuralProperty(companyType, "Address", new EdmComplexTypeReference(addressType, true))); model.AddElement(companyType); EdmSingleton company = new EdmSingleton(defaultContainer, "Company", companyType); defaultContainer.AddElement(company); var publicCompanyType = new EdmEntityType(ns, "PublicCompany", /*baseType*/ companyType, /*isAbstract*/ false, /*isOpen*/ true); publicCompanyType.AddProperty(new EdmStructuralProperty(publicCompanyType, "StockExchange", EdmCoreModel.Instance.GetString(true))); model.AddElement(publicCompanyType); EdmSingleton publicCompany = new EdmSingleton(defaultContainer, "PublicCompany", companyType); defaultContainer.AddElement(publicCompany); var assetType = new EdmEntityType(ns, "Asset", /*baseType*/ null, /*isAbstract*/ false, /*isOpen*/ false); var assetId = new EdmStructuralProperty(assetType, "AssetID", EdmCoreModel.Instance.GetInt32(false)); assetType.AddProperty(assetId); assetType.AddKeys(assetId); assetType.AddProperty(new EdmStructuralProperty(assetType, "Name", EdmCoreModel.Instance.GetString(true))); assetType.AddProperty(new EdmStructuralProperty(assetType, "Number", EdmCoreModel.Instance.GetInt32(false))); model.AddElement(assetType); var clubType = new EdmEntityType(ns, "Club", /*baseType*/ null, /*isAbstract*/ false, /*isOpen*/ false); var clubId = new EdmStructuralProperty(clubType, "ClubID", EdmCoreModel.Instance.GetInt32(false)); clubType.AddProperty(clubId); clubType.AddKeys(clubId); clubType.AddProperty(new EdmStructuralProperty(clubType, "Name", EdmCoreModel.Instance.GetString(true))); model.AddElement(clubType); var labourUnionType = new EdmEntityType(ns, "LabourUnion", /*baseType*/ null, /*isAbstract*/ false, /*isOpen*/ false); var labourUnionId = new EdmStructuralProperty(labourUnionType, "LabourUnionID", EdmCoreModel.Instance.GetInt32(false)); labourUnionType.AddProperty(labourUnionId); labourUnionType.AddKeys(labourUnionId); labourUnionType.AddProperty(new EdmStructuralProperty(labourUnionType, "Name", EdmCoreModel.Instance.GetString(true))); model.AddElement(labourUnionType); EdmSingleton labourUnion = new EdmSingleton(defaultContainer, "LabourUnion", labourUnionType); defaultContainer.AddElement(labourUnion); var companyEmployeeNavigation = companyType.AddBidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Employees", Target = employeeType, TargetMultiplicity = EdmMultiplicity.Many }, new EdmNavigationPropertyInfo() { Name = "Company", Target = companyType, TargetMultiplicity = EdmMultiplicity.One }); var companyCustomerNavigation = companyType.AddBidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "VipCustomer", Target = customerType, TargetMultiplicity = EdmMultiplicity.One }, new EdmNavigationPropertyInfo() { Name = "Company", Target = companyType, TargetMultiplicity = EdmMultiplicity.One }); var companyDepartmentsNavigation = companyType.AddBidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Departments", Target = departmentType, TargetMultiplicity = EdmMultiplicity.Many }, new EdmNavigationPropertyInfo() { Name = "Company", Target = companyType, TargetMultiplicity = EdmMultiplicity.One }); var companyCoreDepartmentNavigation = companyType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "CoreDepartment", Target = departmentType, TargetMultiplicity = EdmMultiplicity.One }); var publicCompanyAssetNavigation = publicCompanyType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Assets", Target = assetType, TargetMultiplicity = EdmMultiplicity.Many, ContainsTarget = true }); var publicCompanyClubNavigation = publicCompanyType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Club", Target = clubType, TargetMultiplicity = EdmMultiplicity.One, ContainsTarget = true }); var publicCompanyLabourUnionNavigation = publicCompanyType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "LabourUnion", Target = labourUnionType, TargetMultiplicity = EdmMultiplicity.One }); //vipCustomer->orders ((EdmSingleton)vipCustomer).AddNavigationTarget(ordersNavigation, orderSet); //vipCustomer->people ((EdmSingleton)vipCustomer).AddNavigationTarget(parentNavigation, personSet); ((EdmSingleton)boss).AddNavigationTarget(parentNavigation, personSet); //employeeSet<->company ((EdmSingleton)company).AddNavigationTarget(companyEmployeeNavigation, employeeSet); ((EdmEntitySet)employeeSet).AddNavigationTarget(companyEmployeeNavigation.Partner, company); //company<->vipcustomer ((EdmSingleton)company).AddNavigationTarget(companyCustomerNavigation, vipCustomer); ((EdmSingleton)vipCustomer).AddNavigationTarget(companyCustomerNavigation.Partner, company); //company<->departments ((EdmSingleton)company).AddNavigationTarget(companyDepartmentsNavigation, departments); ((EdmEntitySet)departments).AddNavigationTarget(companyDepartmentsNavigation.Partner, company); //company<-> Single department ((EdmSingleton)company).AddNavigationTarget(companyCoreDepartmentNavigation, departments); //publicCompany<-> Singleton ((EdmSingleton)publicCompany).AddNavigationTarget(publicCompanyLabourUnionNavigation, labourUnion); #region Action/Function //Bound Action : bound to Entity, return EnumType var productAddAccessRightAction = new EdmAction(ns, "AddAccessRight", new EdmEnumTypeReference(accessLevelType, true), true, null); productAddAccessRightAction.AddParameter("product", new EdmEntityTypeReference(productType, false)); productAddAccessRightAction.AddParameter("accessRight", new EdmEnumTypeReference(accessLevelType, true)); model.AddElement(productAddAccessRightAction); //Bound Action : Bound to Singleton, Primitive Parameter return Primitive Type EdmAction increaseRevenue = new EdmAction(ns, "IncreaseRevenue", EdmCoreModel.Instance.GetInt64(false), /*isBound*/true, /*entitySetPathExpression*/null); increaseRevenue.AddParameter(new EdmOperationParameter(increaseRevenue, "p", new EdmEntityTypeReference(companyType, false))); increaseRevenue.AddParameter(new EdmOperationParameter(increaseRevenue, "IncreaseValue", EdmCoreModel.Instance.GetInt64(true))); model.AddElement(increaseRevenue); //Bound Action : Bound to Entity, Collection Of ComplexType Parameter, Return Entity var resetAddressAction = new EdmAction(ns, "ResetAddress", new EdmEntityTypeReference(personType, false), true, new EdmPathExpression("person")); resetAddressAction.AddParameter("person", new EdmEntityTypeReference(personType, false)); resetAddressAction.AddParameter("addresses", new EdmCollectionTypeReference(new EdmCollectionType(new EdmComplexTypeReference(addressType, true)))); resetAddressAction.AddParameter("index", EdmCoreModel.Instance.GetInt32(false)); model.AddElement(resetAddressAction); //Bound Action : Bound to Entity, EntityType Parameter, Return Entity var placeOrderAction = new EdmAction(ns, "PlaceOrder", new EdmEntityTypeReference(orderType, false), true, new EdmPathExpression("customer/Orders")); placeOrderAction.AddParameter("customer", new EdmEntityTypeReference(customerType, false)); placeOrderAction.AddParameter("order", new EdmEntityTypeReference(orderType, false)); model.AddElement(placeOrderAction); //Bound Action : Bound to Entity, Collection Of EntityType Parameter, Return Collection of Entity var placeOrdersAction = new EdmAction(ns, "PlaceOrders", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(orderType, false))), true, new EdmPathExpression("customer/Orders")); placeOrdersAction.AddParameter("customer", new EdmEntityTypeReference(customerType, false)); placeOrdersAction.AddParameter("orders", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(orderType, false)))); model.AddElement(placeOrdersAction); //Bound Action : Bound to collection of EntitySet, Return Collection of Entity var discountSeveralProductAction = new EdmAction(ns, "Discount", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(productType, false))), true, new EdmPathExpression("products")); discountSeveralProductAction.AddParameter("products", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(productType, false)))); discountSeveralProductAction.AddParameter("percentage", EdmCoreModel.Instance.GetInt32(false)); model.AddElement(discountSeveralProductAction); //Bound Action : Bound to Entity, return void var changeLabourUnionNameAction = new EdmAction(ns, "ChangeLabourUnionName", null, true, null); changeLabourUnionNameAction.AddParameter("labourUnion", new EdmEntityTypeReference(labourUnionType, false)); changeLabourUnionNameAction.AddParameter("name", EdmCoreModel.Instance.GetString(true)); model.AddElement(changeLabourUnionNameAction); //Bound Action : Bound to Entity, return order take Date/TimeOfDay as Parameter var changeShipTimeAndDate = new EdmAction(ns, "ChangeShipTimeAndDate", new EdmEntityTypeReference(orderType, false), true, new EdmPathExpression("order")); changeShipTimeAndDate.AddParameter("order", new EdmEntityTypeReference(orderType, false)); changeShipTimeAndDate.AddParameter("date", EdmCoreModel.Instance.GetDate(false)); changeShipTimeAndDate.AddParameter("time", EdmCoreModel.Instance.GetTimeOfDay(false)); model.AddElement(changeShipTimeAndDate); //UnBound Action : Primitive parameter, Return void var discountAction = new EdmAction(ns, "Discount", null, false, null); discountAction.AddParameter("percentage", EdmCoreModel.Instance.GetInt32(false)); model.AddElement(discountAction); defaultContainer.AddActionImport(discountAction); //UnBound Action : Collection of Primitive parameter, Return Collection of Primitive var resetBossEmailAction = new EdmAction(ns, "ResetBossEmail", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(false))), false, null); resetBossEmailAction.AddParameter("emails", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(false)))); model.AddElement(resetBossEmailAction); defaultContainer.AddActionImport(resetBossEmailAction); //UnBound Action : ComplexType parameter, Return ComplexType var resetBossAddressAction = new EdmAction(ns, "ResetBossAddress", new EdmComplexTypeReference(addressType, false), false, null); resetBossAddressAction.AddParameter("address", new EdmComplexTypeReference(addressType, false)); model.AddElement(resetBossAddressAction); defaultContainer.AddActionImport(resetBossAddressAction); //UnBound Action: ResetDataSource var resetDataSourceAction = new EdmAction(ns, "ResetDataSource", null, false, null); model.AddElement(resetDataSourceAction); defaultContainer.AddActionImport(resetDataSourceAction); //Bound Function : Bound to Singleton, Return PrimitiveType EdmFunction getCompanyEmployeeCount = new EdmFunction(ns, "GetEmployeesCount", EdmCoreModel.Instance.GetInt32(false), /*isBound*/true, /*entitySetPathExpression*/null, /*isComposable*/false); getCompanyEmployeeCount.AddParameter(new EdmOperationParameter(getCompanyEmployeeCount, "p", new EdmEntityTypeReference(companyType, false))); model.AddElement(getCompanyEmployeeCount); //Bound Function : Bound to Entity, Return CollectionOfEntity var getProductDetailsFunction = new EdmFunction(ns, "GetProductDetails", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(productDetailType, false))), true, new EdmPathExpression("product/Details"), true); getProductDetailsFunction.AddParameter("product", new EdmEntityTypeReference(productType, false)); getProductDetailsFunction.AddParameter("count", EdmCoreModel.Instance.GetInt32(true)); model.AddElement(getProductDetailsFunction); //Bound Function : Bound to Entity, Return Entity var getRelatedProductFunction = new EdmFunction(ns, "GetRelatedProduct", new EdmEntityTypeReference(productType, false), true, new EdmPathExpression("productDetail/RelatedProduct"), true); getRelatedProductFunction.AddParameter("productDetail", new EdmEntityTypeReference(productDetailType, false)); model.AddElement(getRelatedProductFunction); //Bound Function : Bound to Entity, Return Collection of Abstract Entity var getOrderAndOrderDetails = new EdmFunction(ns, "getOrderAndOrderDetails", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(abstractType, false))), true, new EdmPathExpression("customer/Orders"), true); getOrderAndOrderDetails.AddParameter("customer", new EdmEntityTypeReference(customerType, false)); model.AddElement(getOrderAndOrderDetails); //Bound Function : Bound to CollectionOfEntity, Return Entity var getSeniorEmployees = new EdmFunction(ns, "GetSeniorEmployees", new EdmEntityTypeReference(employeeType, true), true, new EdmPathExpression("employees"), true); getSeniorEmployees.AddParameter("employees", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(employeeType, false)))); model.AddElement(getSeniorEmployees); //Bound Function : Bound to Order, Return Edm.Date var getOrderShipDate = new EdmFunction(ns, "GetShipDate", EdmCoreModel.Instance.GetDate(false), true, null, false); getOrderShipDate.AddParameter("order", new EdmEntityTypeReference(orderType, false)); model.AddElement(getOrderShipDate); //Bound Function : Bound to Order, Return Edm.TimeOfDay var getOrderShipTime = new EdmFunction(ns, "GetShipTime", EdmCoreModel.Instance.GetTimeOfDay(false), true, null, false); getOrderShipTime.AddParameter("order", new EdmEntityTypeReference(orderType, false)); model.AddElement(getOrderShipTime); //Bound Function : Bound to Order, Parameter: Edm.TimeOfDay, Return Edm.Boolean var checkOrderShipTime = new EdmFunction(ns, "CheckShipTime", EdmCoreModel.Instance.GetBoolean(false), true, null, false); checkOrderShipTime.AddParameter("order", new EdmEntityTypeReference(orderType, false)); checkOrderShipTime.AddParameter("time", EdmCoreModel.Instance.GetTimeOfDay(false)); model.AddElement(checkOrderShipTime); //Bound Function : Bound to Order, Parameter: Edm.Date, Return Edm.Boolean var checkOrderShipDate = new EdmFunction(ns, "CheckShipDate", EdmCoreModel.Instance.GetBoolean(false), true, null, false); checkOrderShipDate.AddParameter("order", new EdmEntityTypeReference(orderType, false)); checkOrderShipDate.AddParameter("date", EdmCoreModel.Instance.GetDate(false)); model.AddElement(checkOrderShipDate); //UnBound Function : Return EnumType var defaultColorFunction = new EdmFunction(ns, "GetDefaultColor", new EdmEnumTypeReference(colorType, true), false, null, true); model.AddElement(defaultColorFunction); defaultContainer.AddFunctionImport("GetDefaultColor", defaultColorFunction, null, true); //UnBound Function : Complex Parameter, Return Entity var getPersonFunction = new EdmFunction(ns, "GetPerson", new EdmEntityTypeReference(personType, false), false, null, true); getPersonFunction.AddParameter("address", new EdmComplexTypeReference(addressType, false)); model.AddElement(getPersonFunction); defaultContainer.AddFunctionImport("GetPerson", getPersonFunction, new EdmEntitySetReferenceExpression(personSet), true); //UnBound Function : Primtive Parameter, Return Entity var getPersonFunction2 = new EdmFunction(ns, "GetPerson2", new EdmEntityTypeReference(personType, false), false, null, true); getPersonFunction2.AddParameter("city", EdmCoreModel.Instance.GetString(false)); model.AddElement(getPersonFunction2); defaultContainer.AddFunctionImport("GetPerson2", getPersonFunction2, new EdmEntitySetReferenceExpression(personSet), true); //UnBound Function : Return CollectionOfEntity var getAllProductsFunction = new EdmFunction(ns, "GetAllProducts", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(productType, false))), false, null, true); model.AddElement(getAllProductsFunction); defaultContainer.AddFunctionImport("GetAllProducts", getAllProductsFunction, new EdmEntitySetReferenceExpression(productSet), true); //UnBound Function : Multi ParameterS Return Collection Of ComplexType var getBossEmailsFunction = new EdmFunction(ns, "GetBossEmails", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(false))), false, null, false); getBossEmailsFunction.AddParameter("start", EdmCoreModel.Instance.GetInt32(false)); getBossEmailsFunction.AddParameter("count", EdmCoreModel.Instance.GetInt32(false)); model.AddElement(getBossEmailsFunction); defaultContainer.AddFunctionImport(getBossEmailsFunction.Name, getBossEmailsFunction, null, true); var getProductsByAccessLevelFunction = new EdmFunction(ns, "GetProductsByAccessLevel", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(false))), false, null, false); getProductsByAccessLevelFunction.AddParameter("accessLevel", new EdmEnumTypeReference(accessLevelType, false)); model.AddElement(getProductsByAccessLevelFunction); defaultContainer.AddFunctionImport(getProductsByAccessLevelFunction.Name, getProductsByAccessLevelFunction, null, true); #endregion #endregion #region For containment var accountInfoType = new EdmComplexType(ns, "AccountInfo", null, false, true); accountInfoType.AddProperty(new EdmStructuralProperty(accountInfoType, "FirstName", EdmCoreModel.Instance.GetString(false))); accountInfoType.AddProperty(new EdmStructuralProperty(accountInfoType, "LastName", EdmCoreModel.Instance.GetString(false))); var accountType = new EdmEntityType(ns, "Account"); var accountIdProperty = new EdmStructuralProperty(accountType, "AccountID", EdmCoreModel.Instance.GetInt32(false)); accountType.AddProperty(accountIdProperty); accountType.AddKeys(accountIdProperty); accountType.AddProperty(new EdmStructuralProperty(accountType, "CountryRegion", EdmCoreModel.Instance.GetString(false))); accountType.AddProperty(new EdmStructuralProperty(accountType, "AccountInfo", new EdmComplexTypeReference(accountInfoType, true))); var giftCardType = new EdmEntityType(ns, "GiftCard"); var giftCardIdProperty = new EdmStructuralProperty(giftCardType, "GiftCardID", EdmCoreModel.Instance.GetInt32(false)); giftCardType.AddProperty(giftCardIdProperty); giftCardType.AddKeys(giftCardIdProperty); giftCardType.AddProperty(new EdmStructuralProperty(giftCardType, "GiftCardNO", EdmCoreModel.Instance.GetString(false))); giftCardType.AddProperty(new EdmStructuralProperty(giftCardType, "Amount", EdmCoreModel.Instance.GetDouble(false))); giftCardType.AddProperty(new EdmStructuralProperty(giftCardType, "ExperationDate", EdmCoreModel.Instance.GetDateTimeOffset(false))); giftCardType.AddProperty(new EdmStructuralProperty(giftCardType, "OwnerName", EdmCoreModel.Instance.GetString(true))); var paymentInstrumentType = new EdmEntityType(ns, "PaymentInstrument"); var paymentInstrumentIdProperty = new EdmStructuralProperty(paymentInstrumentType, "PaymentInstrumentID", EdmCoreModel.Instance.GetInt32(false)); paymentInstrumentType.AddProperty(paymentInstrumentIdProperty); paymentInstrumentType.AddKeys(paymentInstrumentIdProperty); paymentInstrumentType.AddProperty(new EdmStructuralProperty(paymentInstrumentType, "FriendlyName", EdmCoreModel.Instance.GetString(false))); paymentInstrumentType.AddProperty(new EdmStructuralProperty(paymentInstrumentType, "CreatedDate", EdmCoreModel.Instance.GetDateTimeOffset(false))); var creditCardType = new EdmEntityType(ns, "CreditCardPI", paymentInstrumentType); creditCardType.AddProperty(new EdmStructuralProperty(creditCardType, "CardNumber", EdmCoreModel.Instance.GetString(false))); creditCardType.AddProperty(new EdmStructuralProperty(creditCardType, "CVV", EdmCoreModel.Instance.GetString(false))); creditCardType.AddProperty(new EdmStructuralProperty(creditCardType, "HolderName", EdmCoreModel.Instance.GetString(false))); creditCardType.AddProperty(new EdmStructuralProperty(creditCardType, "Balance", EdmCoreModel.Instance.GetDouble(false))); creditCardType.AddProperty(new EdmStructuralProperty(creditCardType, "ExperationDate", EdmCoreModel.Instance.GetDateTimeOffset(false))); var storedPIType = new EdmEntityType(ns, "StoredPI"); var storedPIIdProperty = new EdmStructuralProperty(storedPIType, "StoredPIID", EdmCoreModel.Instance.GetInt32(false)); storedPIType.AddProperty(storedPIIdProperty); storedPIType.AddKeys(storedPIIdProperty); storedPIType.AddProperty(new EdmStructuralProperty(storedPIType, "PIName", EdmCoreModel.Instance.GetString(false))); storedPIType.AddProperty(new EdmStructuralProperty(storedPIType, "PIType", EdmCoreModel.Instance.GetString(false))); storedPIType.AddProperty(new EdmStructuralProperty(storedPIType, "CreatedDate", EdmCoreModel.Instance.GetDateTimeOffset(false))); var statementType = new EdmEntityType(ns, "Statement"); var statementIdProperty = new EdmStructuralProperty(statementType, "StatementID", EdmCoreModel.Instance.GetInt32(false)); statementType.AddProperty(statementIdProperty); statementType.AddKeys(statementIdProperty); statementType.AddProperty(new EdmStructuralProperty(statementType, "TransactionType", EdmCoreModel.Instance.GetString(false))); statementType.AddProperty(new EdmStructuralProperty(statementType, "TransactionDescription", EdmCoreModel.Instance.GetString(false))); statementType.AddProperty(new EdmStructuralProperty(statementType, "Amount", EdmCoreModel.Instance.GetDouble(false))); var creditRecordType = new EdmEntityType(ns, "CreditRecord"); var creditRecordIdProperty = new EdmStructuralProperty(creditRecordType, "CreditRecordID", EdmCoreModel.Instance.GetInt32(false)); creditRecordType.AddProperty(creditRecordIdProperty); creditRecordType.AddKeys(creditRecordIdProperty); creditRecordType.AddProperty(new EdmStructuralProperty(creditRecordType, "IsGood", EdmCoreModel.Instance.GetBoolean(false))); creditRecordType.AddProperty(new EdmStructuralProperty(creditRecordType, "Reason", EdmCoreModel.Instance.GetString(false))); creditRecordType.AddProperty(new EdmStructuralProperty(creditRecordType, "CreatedDate", EdmCoreModel.Instance.GetDateTimeOffset(false))); var subscriptionType = new EdmEntityType(ns, "Subscription"); var subscriptionIdProperty = new EdmStructuralProperty(subscriptionType, "SubscriptionID", EdmCoreModel.Instance.GetInt32(false)); subscriptionType.AddProperty(subscriptionIdProperty); subscriptionType.AddKeys(subscriptionIdProperty); subscriptionType.AddProperty(new EdmStructuralProperty(subscriptionType, "TemplateGuid", EdmCoreModel.Instance.GetString(false))); subscriptionType.AddProperty(new EdmStructuralProperty(subscriptionType, "Title", EdmCoreModel.Instance.GetString(false))); subscriptionType.AddProperty(new EdmStructuralProperty(subscriptionType, "Category", EdmCoreModel.Instance.GetString(false))); subscriptionType.AddProperty(new EdmStructuralProperty(subscriptionType, "CreatedDate", EdmCoreModel.Instance.GetDateTimeOffset(false))); #region Functions/Actions var giftCardAmountFunction = new EdmFunction(ns, "GetActualAmount", EdmCoreModel.Instance.GetDouble(false), true, null, false); giftCardAmountFunction.AddParameter("giftcard", new EdmEntityTypeReference(giftCardType, false)); giftCardAmountFunction.AddParameter("bonusRate", EdmCoreModel.Instance.GetDouble(true)); model.AddElement(giftCardAmountFunction); var accountDefaultPIFunction = new EdmFunction(ns, "GetDefaultPI", new EdmEntityTypeReference(paymentInstrumentType, true), true, new EdmPathExpression("account/MyPaymentInstruments"), false); accountDefaultPIFunction.AddParameter("account", new EdmEntityTypeReference(accountType, false)); model.AddElement(accountDefaultPIFunction); var accountRefreshDefaultPIAction = new EdmAction(ns, "RefreshDefaultPI", new EdmEntityTypeReference(paymentInstrumentType, true), true, new EdmPathExpression("account/MyPaymentInstruments")); accountRefreshDefaultPIAction.AddParameter("account", new EdmEntityTypeReference(accountType, false)); accountRefreshDefaultPIAction.AddParameter("newDate", EdmCoreModel.Instance.GetDateTimeOffset(true)); model.AddElement(accountRefreshDefaultPIAction); //Bound Function : Bound to Entity, Return ComplexType var getHomeAddressFunction = new EdmFunction(ns, "GetHomeAddress", new EdmComplexTypeReference(homeAddressType, false), true, null, true); getHomeAddressFunction.AddParameter("person", new EdmEntityTypeReference(personType, false)); model.AddElement(getHomeAddressFunction); //Bound Function : Bound to Entity, Return ComplexType var getAccountInfoFunction = new EdmFunction(ns, "GetAccountInfo", new EdmComplexTypeReference(accountInfoType, false), true, null, true); getAccountInfoFunction.AddParameter("account", new EdmEntityTypeReference(accountType, false)); model.AddElement(getAccountInfoFunction); #endregion var accountGiftCardNavigation = accountType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "MyGiftCard", Target = giftCardType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne, ContainsTarget = true }); var accountPIsNavigation = accountType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "MyPaymentInstruments", Target = paymentInstrumentType, TargetMultiplicity = EdmMultiplicity.Many, ContainsTarget = true }); var accountActiveSubsNavigation = accountType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "ActiveSubscriptions", Target = subscriptionType, TargetMultiplicity = EdmMultiplicity.Many, ContainsTarget = true }); var accountAvailableSubsTemplatesNavigation = accountType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "AvailableSubscriptionTemplatess", Target = subscriptionType, TargetMultiplicity = EdmMultiplicity.Many, ContainsTarget = false }); var piStoredNavigation = paymentInstrumentType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "TheStoredPI", Target = storedPIType, TargetMultiplicity = EdmMultiplicity.One, ContainsTarget = false }); var piStatementsNavigation = paymentInstrumentType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "BillingStatements", Target = statementType, TargetMultiplicity = EdmMultiplicity.Many, ContainsTarget = true }); var piBackupStoredPINavigation = paymentInstrumentType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "BackupStoredPI", Target = storedPIType, TargetMultiplicity = EdmMultiplicity.One, ContainsTarget = false }); var creditCardCreditRecordNavigation = creditCardType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "CreditRecords", Target = creditRecordType, TargetMultiplicity = EdmMultiplicity.Many, ContainsTarget = true }); model.AddElement(accountInfoType); model.AddElement(accountType); model.AddElement(giftCardType); model.AddElement(paymentInstrumentType); model.AddElement(creditCardType); model.AddElement(storedPIType); model.AddElement(statementType); model.AddElement(creditRecordType); model.AddElement(subscriptionType); var accountSet = new EdmEntitySet(defaultContainer, "Accounts", accountType); defaultContainer.AddElement(accountSet); var storedPISet = new EdmEntitySet(defaultContainer, "StoredPIs", storedPIType); defaultContainer.AddElement(storedPISet); var subscriptionTemplatesSet = new EdmEntitySet(defaultContainer, "SubscriptionTemplates", subscriptionType); defaultContainer.AddElement(subscriptionTemplatesSet); var defaultStoredPI = new EdmSingleton(defaultContainer, "DefaultStoredPI", storedPIType); defaultContainer.AddElement(defaultStoredPI); ((EdmEntitySet)accountSet).AddNavigationTarget(piStoredNavigation, storedPISet); ((EdmEntitySet)accountSet).AddNavigationTarget(accountAvailableSubsTemplatesNavigation, subscriptionTemplatesSet); ((EdmEntitySet)accountSet).AddNavigationTarget(piBackupStoredPINavigation, defaultStoredPI); #endregion IEnumerable<EdmError> errors = null; model.Validate(out errors); //TODO: Fix the errors return model; }
/// <summary>Adds a singleton to the metadata definition.</summary> /// <param name="name">The name of the singleton to add.</param> /// <param name="entityType">The type of entity in the singleton.</param> /// <returns>The newly created singleton.</returns> public IEdmSingleton AddSingleton(string name, IEdmEntityType entityType) { if (entityType.TypeKind != EdmTypeKind.Entity) { throw new ArgumentException("The type specified as the base type of a singleton is not an entity type."); } EdmSingleton singleton = new EdmSingleton(this, name, entityType); this.SetAnnotationValue<IEdmSingleton>(entityType, singleton); this.singletons.Add(name, singleton); return singleton; }
private void OpenTypeTestSetting() { EdmModel tmpModel = new EdmModel(); this.webType = new EdmEntityType("NS", "Web", null, false, true); this.webType.AddStructuralProperty("WebId", EdmPrimitiveTypeKind.Int32); tmpModel.AddElement(this.webType); this.defaultContainer = new EdmEntityContainer("NS", "DefaultContainer_sub"); tmpModel.AddElement(defaultContainer); this.singleton = new EdmSingleton(defaultContainer, "MySingleton", this.webType); this.defaultContainer.AddElement(this.singleton); this.userModel = TestUtils.WrapReferencedModelsToMainModel("NS", "DefaultContainer", tmpModel); this.referencedModel = tmpModel; }
private void InitializeEdmModel() { this.edmModel = new EdmModel(); EdmEntityContainer defaultContainer = new EdmEntityContainer("TestModel", "DefaultContainer"); this.edmModel.AddElement(defaultContainer); EdmComplexType addressType = new EdmComplexType("TestModel", "Address"); addressType.AddStructuralProperty("Street", EdmCoreModel.Instance.GetString(/*isNullable*/false)); addressType.AddStructuralProperty("Zip", EdmCoreModel.Instance.GetString(/*isNullable*/false)); this.cityType = new EdmEntityType("TestModel", "City"); EdmStructuralProperty cityIdProperty = cityType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(/*isNullable*/false)); cityType.AddKeys(cityIdProperty); cityType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(/*isNullable*/false)); cityType.AddStructuralProperty("Size", EdmCoreModel.Instance.GetInt32(/*isNullable*/false)); cityType.AddStructuralProperty("Restaurants", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetString(/*isNullable*/false))); cityType.AddStructuralProperty("Address", new EdmComplexTypeReference(addressType, true)); this.edmModel.AddElement(cityType); this.capitolCityType = new EdmEntityType("TestModel", "CapitolCity", cityType); capitolCityType.AddStructuralProperty("CapitolType", EdmCoreModel.Instance.GetString( /*isNullable*/false)); this.edmModel.AddElement(capitolCityType); EdmEntityType districtType = new EdmEntityType("TestModel", "District"); EdmStructuralProperty districtIdProperty = districtType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(/*isNullable*/false)); districtType.AddKeys(districtIdProperty); districtType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(/*isNullable*/false)); districtType.AddStructuralProperty("Zip", EdmCoreModel.Instance.GetInt32(/*isNullable*/false)); this.edmModel.AddElement(districtType); cityType.AddBidirectionalNavigation( new EdmNavigationPropertyInfo { Name = "Districts", Target = districtType, TargetMultiplicity = EdmMultiplicity.Many }, new EdmNavigationPropertyInfo { Name = "City", Target = cityType, TargetMultiplicity = EdmMultiplicity.One }); cityType.NavigationProperties().Single(np => np.Name == "Districts"); capitolCityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "CapitolDistrict", Target = districtType, TargetMultiplicity = EdmMultiplicity.One }); capitolCityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "OutlyingDistricts", Target = districtType, TargetMultiplicity = EdmMultiplicity.Many }); this.citySet = defaultContainer.AddEntitySet("Cities", cityType); defaultContainer.AddEntitySet("Districts", districtType); this.singletonCity = defaultContainer.AddSingleton("SingletonCity", cityType); }
public static IEdmModel CreateModel(string ns) { EdmModel model = new EdmModel(); var defaultContainer = new EdmEntityContainer(ns, "DefaultContainer"); model.AddElement(defaultContainer); var orderDetail = new EdmComplexType(ns, "orderDetail"); orderDetail.AddProperty(new EdmStructuralProperty(orderDetail, "amount", EdmCoreModel.Instance.GetDecimal(false))); orderDetail.AddProperty(new EdmStructuralProperty(orderDetail, "quantity", EdmCoreModel.Instance.GetInt32(false))); model.AddElement(orderDetail); var billingType = new EdmEnumType(ns, "billingType", EdmPrimitiveTypeKind.Int64, false); billingType.AddMember("fund", new EdmIntegerConstant(0)); billingType.AddMember("refund", new EdmIntegerConstant(1)); billingType.AddMember("chargeback", new EdmIntegerConstant(2)); model.AddElement(billingType); var category = new EdmEnumType(ns, "category", true); category.AddMember("toy", new EdmIntegerConstant(1)); category.AddMember("food", new EdmIntegerConstant(2)); category.AddMember("cloth", new EdmIntegerConstant(4)); category.AddMember("drink", new EdmIntegerConstant(8)); category.AddMember("computer", new EdmIntegerConstant(16)); model.AddElement(category); var namedObject = new EdmEntityType(ns, "namedObject"); var idProperty = new EdmStructuralProperty(namedObject, "id", EdmCoreModel.Instance.GetInt32(false)); namedObject.AddProperty(idProperty); namedObject.AddKeys(idProperty); namedObject.AddProperty(new EdmStructuralProperty(namedObject, "name", EdmCoreModel.Instance.GetString(false))); model.AddElement(namedObject); var order = new EdmEntityType(ns, "order", namedObject); order.AddProperty(new EdmStructuralProperty(order, "description", EdmCoreModel.Instance.GetString(false))); order.AddProperty(new EdmStructuralProperty(order, "detail", new EdmComplexTypeReference(orderDetail, true))); order.AddProperty(new EdmStructuralProperty(order, "lineItems", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(false))))); order.AddProperty(new EdmStructuralProperty(order, "categories", new EdmEnumTypeReference(category, false))); model.AddElement(order); var billingRecord = new EdmEntityType(ns, "billingRecord", namedObject); billingRecord.AddProperty(new EdmStructuralProperty(billingRecord, "amount", EdmCoreModel.Instance.GetDecimal(false))); billingRecord.AddProperty(new EdmStructuralProperty(billingRecord, "type", new EdmEnumTypeReference(billingType, false))); model.AddElement(billingRecord); var store = new EdmEntityType(ns, "store", namedObject); store.AddProperty(new EdmStructuralProperty(store, "address", EdmCoreModel.Instance.GetString(false))); model.AddElement(store); var orders = new EdmEntitySet(defaultContainer, "orders", order); defaultContainer.AddElement(orders); var billingRecords = new EdmEntitySet(defaultContainer, "billingRecords", billingRecord); defaultContainer.AddElement(billingRecords); var myStore = new EdmSingleton(defaultContainer, "myStore", store); defaultContainer.AddElement(myStore); var order2billingRecord = order.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "billingRecords", Target = billingRecord, TargetMultiplicity = EdmMultiplicity.Many }); ((EdmEntitySet)orders).AddNavigationTarget(order2billingRecord, billingRecords); IEnumerable<EdmError> errors = null; model.Validate(out errors); return model; }
/// <summary> /// Creates and adds an singleton to this entity container. /// </summary> /// <param name="name">Name of the singleton.</param> /// <param name="entityType">The entity type of this singleton.</param> /// <returns>Created singleton.</returns> public virtual EdmSingleton AddSingleton(string name, IEdmEntityType entityType) { EdmSingleton singleton = new EdmSingleton(this, name, entityType); this.AddElement(singleton); return singleton; }
public void GenerateFunctionLink_GeneratesLinkWithDownCast_IfElementTypeDerivesFromBindingParameterType_ForSingleton() { // Arrange IEdmSingleton me = new EdmSingleton(_model.Container, "Me", _model.SpecialCustomer); HttpRequestMessage request = GetODataRequest(_model.Model); var serializerContext = new ODataSerializerContext { Model = _model.Model, NavigationSource = me, Url = request.GetUrlHelper() }; var entityContext = new EntityInstanceContext(serializerContext, _model.SpecialCustomer.AsReference(), new { ID = 42 }); // Act Uri link = entityContext.GenerateFunctionLink(_model.IsCustomerUpgraded); // Assert Assert.Equal("http://localhost/Me/NS.Customer/IsUpgradedWithParam(entity=@entity,city=@city)", link.AbsoluteUri); }
public BatchRoundtripJsonLightTests() { this.userModel = new EdmModel(); this.webType = new EdmEntityType("NS", "Web"); this.webType.AddStructuralProperty("WebId", EdmPrimitiveTypeKind.Int32); this.webType.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); this.userModel.AddElement(this.webType); this.defaultContainer = new EdmEntityContainer("NS", "DefaultContainer"); this.userModel.AddElement(defaultContainer); this.singleton = new EdmSingleton(defaultContainer, "MySingleton", this.webType); this.defaultContainer.AddElement(this.singleton); }