本文整理汇总了C#中Microsoft.OData.Edm.Library.EdmEntityContainer.AddActionImport方法的典型用法代码示例。如果您正苦于以下问题:C# EdmEntityContainer.AddActionImport方法的具体用法?C# EdmEntityContainer.AddActionImport怎么用?C# EdmEntityContainer.AddActionImport使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.OData.Edm.Library.EdmEntityContainer
的用法示例。
在下文中一共展示了EdmEntityContainer.AddActionImport方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateServiceEdmModel
public static IEdmModel CreateServiceEdmModel(string ns)
{
EdmModel model = new EdmModel();
var defaultContainer = new EdmEntityContainer(ns, "PerfInMemoryContainer");
model.AddElement(defaultContainer);
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, "Age", EdmCoreModel.Instance.GetInt32(false)));
model.AddElement(personType);
var simplePersonSet = new EdmEntitySet(defaultContainer, "SimplePeopleSet", personType);
defaultContainer.AddElement(simplePersonSet);
var largetPersonSet = new EdmEntitySet(defaultContainer, "LargePeopleSet", personType);
defaultContainer.AddElement(largetPersonSet);
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 companyType = new EdmEntityType(ns, "Company");
var companyId = new EdmStructuralProperty(companyType, "CompanyID", EdmCoreModel.Instance.GetInt32(false));
companyType.AddProperty(companyId);
companyType.AddKeys(companyId);
companyType.AddProperty(new EdmStructuralProperty(companyType, "Name", EdmCoreModel.Instance.GetString(true)));
companyType.AddProperty(new EdmStructuralProperty(companyType, "Address", new EdmComplexTypeReference(addressType, true)));
companyType.AddProperty(new EdmStructuralProperty(companyType, "Revenue", EdmCoreModel.Instance.GetInt32(false)));
model.AddElement(companyType);
var companySet = new EdmEntitySet(defaultContainer, "CompanySet", companyType);
defaultContainer.AddElement(companySet);
var companyEmployeeNavigation = companyType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
{
Name = "Employees",
Target = personType,
TargetMultiplicity = EdmMultiplicity.Many
});
companySet.AddNavigationTarget(companyEmployeeNavigation, largetPersonSet);
// ResetDataSource
var resetDataSourceAction = new EdmAction(ns, "ResetDataSource", null, false, null);
model.AddElement(resetDataSourceAction);
defaultContainer.AddActionImport(resetDataSourceAction);
return model;
}
示例2: EnsureActionImportIsAddedAndWithCorrectSuppliedName
public void EnsureActionImportIsAddedAndWithCorrectSuppliedName()
{
EdmEntityContainer container = new EdmEntityContainer("Default", "Container");
EdmAction action = new EdmAction("DS", "TestAction", EdmCoreModel.Instance.GetBoolean(false));
var actionImport = container.AddActionImport("OtherName", action);
actionImport.Action.Should().Be(action);
actionImport.Name.Should().Be("OtherName");
container.Elements.ToArray()[0].Should().Be(actionImport);
}
示例3: EnsureActionImportIsAddedAndWithCorrectEntitySetExpression
public void EnsureActionImportIsAddedAndWithCorrectEntitySetExpression()
{
EdmEntityContainer container = new EdmEntityContainer("Default", "Container");
EdmAction action = new EdmAction("DS", "TestAction", EdmCoreModel.Instance.GetBoolean(false));
var edmEntitySet = new EdmEntitySet(container, "EntitySet", new EdmEntityType("DS", "TestEntity"));
var entitySetExpression = new EdmEntitySetReferenceExpression(edmEntitySet);
var actionImport = container.AddActionImport("OtherName", action, entitySetExpression);
actionImport.Action.Should().Be(action);
actionImport.Name.Should().Be("OtherName");
actionImport.EntitySet.Should().Be(entitySetExpression);
container.Elements.ToArray()[0].Should().Be(actionImport);
}
示例4: CreateTestModel
private IEdmModel CreateTestModel()
{
EdmModel model = new EdmModel();
EdmEntityContainer defaultContainer = new EdmEntityContainer("TestModel", "Default");
model.AddElement(defaultContainer);
var productType = new EdmEntityType("TestModel", "Product");
EdmStructuralProperty idProperty = new EdmStructuralProperty(productType, "Id", EdmCoreModel.Instance.GetInt32(false));
productType.AddProperty(idProperty);
productType.AddKeys(idProperty);
productType.AddProperty(new EdmStructuralProperty(productType, "Name", EdmCoreModel.Instance.GetString(true)));
model.AddElement(productType);
var customerType = new EdmEntityType("TestModel", "Customer");
idProperty = new EdmStructuralProperty(customerType, "Id", EdmCoreModel.Instance.GetInt32(false));
customerType.AddProperty(idProperty);
customerType.AddKeys(idProperty);
customerType.AddProperty(new EdmStructuralProperty(customerType, "Name", EdmCoreModel.Instance.GetString(true)));
model.AddElement(productType);
defaultContainer.AddEntitySet("Products", productType);
defaultContainer.AddEntitySet("Customers", customerType);
defaultContainer.AddSingleton("SingleProduct", productType);
defaultContainer.AddSingleton("SingleCustomer", customerType);
EdmAction action = new EdmAction("TestModel", "SimpleAction", null/*returnType*/, false /*isBound*/, null /*entitySetPath*/);
model.AddElement(action);
defaultContainer.AddActionImport("SimpleActionImport", action);
EdmFunction function1 = new EdmFunction("TestModel", "SimpleFunction1", EdmCoreModel.Instance.GetInt32(false), false /*isbound*/, null, true);
function1.AddParameter("p1", EdmCoreModel.Instance.GetInt32(false));
defaultContainer.AddFunctionImport("SimpleFunctionImport1", function1);
EdmFunction function2 = new EdmFunction("TestModel", "SimpleFunction2", EdmCoreModel.Instance.GetInt32(false), false /*isbound*/, null, true);
function2.AddParameter("p1", EdmCoreModel.Instance.GetInt32(false));
defaultContainer.AddFunctionImport("SimpleFunctionImport2", function1, null, true /*IncludeInServiceDocument*/);
return model;
}
示例5: ODataJsonLightEntryAndFeedDeserializerTests
static ODataJsonLightEntryAndFeedDeserializerTests()
{
EdmModel tmpModel = new EdmModel();
EdmComplexType complexType = new EdmComplexType("TestNamespace", "TestComplexType");
complexType.AddProperty(new EdmStructuralProperty(complexType, "StringProperty", EdmCoreModel.Instance.GetString(false)));
tmpModel.AddElement(complexType);
EntityType = new EdmEntityType("TestNamespace", "TestEntityType");
tmpModel.AddElement(EntityType);
var keyProperty = new EdmStructuralProperty(EntityType, "ID", EdmCoreModel.Instance.GetInt32(false));
EntityType.AddKeys(new IEdmStructuralProperty[] { keyProperty });
EntityType.AddProperty(keyProperty);
var defaultContainer = new EdmEntityContainer("TestNamespace", "DefaultContainer_sub");
tmpModel.AddElement(defaultContainer);
EntitySet = new EdmEntitySet(defaultContainer, "TestEntitySet", EntityType);
defaultContainer.AddElement(EntitySet);
Action = new EdmAction("TestNamespace", "DoSomething", null, true, null);
Action.AddParameter("p1", new EdmEntityTypeReference(EntityType, false));
tmpModel.AddElement(Action);
ActionImport = defaultContainer.AddActionImport("DoSomething", Action);
var serviceOperationFunction = new EdmFunction("TestNamespace", "ServiceOperation", EdmCoreModel.Instance.GetInt32(true));
defaultContainer.AddFunctionImport("ServiceOperation", serviceOperationFunction);
tmpModel.AddElement(serviceOperationFunction);
tmpModel.AddElement(new EdmTerm("custom", "DateTimeOffsetAnnotation", EdmPrimitiveTypeKind.DateTimeOffset));
tmpModel.AddElement(new EdmTerm("custom", "DateAnnotation", EdmPrimitiveTypeKind.Date));
tmpModel.AddElement(new EdmTerm("custom", "TimeOfDayAnnotation", EdmPrimitiveTypeKind.TimeOfDay));
EdmModel = TestUtils.WrapReferencedModelsToMainModel("TestNamespace", "DefaultContainer", tmpModel);
MessageReaderSettingsReadAndValidateCustomInstanceAnnotations = new ODataMessageReaderSettings { ShouldIncludeAnnotation = ODataUtils.CreateAnnotationFilter("*") };
MessageReaderSettingsIgnoreInstanceAnnotations = new ODataMessageReaderSettings();
}
示例6: CreateModel
public static IEdmModel CreateModel(string ns)
{
EdmModel model = new EdmModel();
var defaultContainer = new EdmEntityContainer(ns, "DefaultContainer");
model.AddElement(defaultContainer);
var nameType = new EdmTypeDefinition(ns, "Name", EdmPrimitiveTypeKind.String);
model.AddElement(nameType);
var addressType = new EdmComplexType(ns, "Address");
addressType.AddProperty(new EdmStructuralProperty(addressType, "Road", new EdmTypeDefinitionReference(nameType, false)));
addressType.AddProperty(new EdmStructuralProperty(addressType, "City", EdmCoreModel.Instance.GetString(false)));
model.AddElement(addressType);
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", new EdmTypeDefinitionReference(nameType, false)));
personType.AddProperty(new EdmStructuralProperty(personType, "LastName", new EdmTypeDefinitionReference(nameType, false)));
personType.AddProperty(new EdmStructuralProperty(personType, "Address", new EdmComplexTypeReference(addressType, true)));
personType.AddProperty(new EdmStructuralProperty(personType, "Descriptions", new EdmCollectionTypeReference(new EdmCollectionType(new EdmTypeDefinitionReference(nameType, false)))));
model.AddElement(personType);
var peopleSet = new EdmEntitySet(defaultContainer, "People", personType);
defaultContainer.AddElement(peopleSet);
var numberComboType = new EdmComplexType(ns, "NumberCombo");
numberComboType.AddProperty(new EdmStructuralProperty(numberComboType, "Small", model.GetUInt16(ns, false)));
numberComboType.AddProperty(new EdmStructuralProperty(numberComboType, "Middle", model.GetUInt32(ns, false)));
numberComboType.AddProperty(new EdmStructuralProperty(numberComboType, "Large", model.GetUInt64(ns, false)));
model.AddElement(numberComboType);
var productType = new EdmEntityType(ns, "Product");
var productIdProperty = new EdmStructuralProperty(productType, "ProductId", model.GetUInt16(ns, false));
productType.AddProperty(productIdProperty);
productType.AddKeys(new IEdmStructuralProperty[] { productIdProperty });
productType.AddProperty(new EdmStructuralProperty(productType, "Quantity", model.GetUInt32(ns, false)));
productType.AddProperty(new EdmStructuralProperty(productType, "NullableUInt32", model.GetUInt32(ns, true)));
productType.AddProperty(new EdmStructuralProperty(productType, "LifeTimeInSeconds", model.GetUInt64(ns, false)));
productType.AddProperty(new EdmStructuralProperty(productType, "TheCombo", new EdmComplexTypeReference(numberComboType, true)));
productType.AddProperty(new EdmStructuralProperty(productType, "LargeNumbers", new EdmCollectionTypeReference(new EdmCollectionType(model.GetUInt64(ns, false)))));
model.AddElement(productType);
var productsSet = new EdmEntitySet(defaultContainer, "Products", productType);
defaultContainer.AddElement(productsSet);
//Bound Function: bound to entity, return defined type
var getFullNameFunction = new EdmFunction(ns, "GetFullName", new EdmTypeDefinitionReference(nameType, false), true, null, false);
getFullNameFunction.AddParameter("person", new EdmEntityTypeReference(personType, false));
getFullNameFunction.AddParameter("nickname", new EdmTypeDefinitionReference(nameType, false));
model.AddElement(getFullNameFunction);
//Bound Action: bound to entity, return UInt64
var extendLifeTimeAction = new EdmAction(ns, "ExtendLifeTime", model.GetUInt64(ns, false), true, null);
extendLifeTimeAction.AddParameter("product", new EdmEntityTypeReference(productType, false));
extendLifeTimeAction.AddParameter("seconds", model.GetUInt32(ns, false));
model.AddElement(extendLifeTimeAction);
//UnBound Action: ResetDataSource
var resetDataSourceAction = new EdmAction(ns, "ResetDataSource", null, false, null);
model.AddElement(resetDataSourceAction);
defaultContainer.AddActionImport(resetDataSourceAction);
IEnumerable<EdmError> errors = null;
model.Validate(out errors);
return model;
}
示例7: ConstructibleModelODataTestModelAnnotationTestWithoutAnnotation
public void ConstructibleModelODataTestModelAnnotationTestWithoutAnnotation()
{
EdmModel model = new EdmModel();
EdmComplexType address = new EdmComplexType("TestModel", "Address");
EdmStructuralProperty addressStreet = address.AddStructuralProperty("Street", EdmCoreModel.Instance.GetString(true));
EdmStructuralProperty addressZip = address.AddStructuralProperty("Zip", EdmCoreModel.Instance.GetInt32(false));
model.AddElement(address);
EdmEntityType person = new EdmEntityType("TestModel", "PersonType");
EdmStructuralProperty personID = person.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(false));
EdmStructuralProperty personName = person.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(false));
EdmStructuralProperty personAddress = person.AddStructuralProperty("Address", new EdmComplexTypeReference(address, false));
EdmStructuralProperty personPicture = person.AddStructuralProperty("Picture", EdmCoreModel.Instance.GetStream(false));
person.AddKeys(personID);
model.AddElement(person);
EdmEntityContainer container = new EdmEntityContainer("TestModel", "DefaultContainer");
EdmEntitySet peopleSet = container.AddEntitySet("People", person);
EdmEntitySet personSet = container.AddEntitySet("PersonType", person);
EdmAction serviceOperationAction = new EdmAction("TestModel", "ServiceOperation1", EdmCoreModel.Instance.GetInt32(false));
EdmOperationParameter a = new EdmOperationParameter(serviceOperationAction, "a", EdmCoreModel.Instance.GetInt32(true));
EdmOperationParameter b = new EdmOperationParameter(serviceOperationAction, "b", EdmCoreModel.Instance.GetString(true));
serviceOperationAction.AddParameter(a);
serviceOperationAction.AddParameter(b);
model.AddElement(serviceOperationAction);
container.AddActionImport("ServiceOperation1", serviceOperationAction);
model.AddElement(container);
this.BasicConstructibleModelTestSerializingStockModel(ODataTestModelBuilder.ODataTestModelAnnotationTestWithoutAnnotations, model);
}
示例8: ConstructibleModelODataTestModelWithFunctionImport
public void ConstructibleModelODataTestModelWithFunctionImport()
{
EdmModel model = new EdmModel();
EdmComplexType complexType = new EdmComplexType("TestModel", "ComplexType");
EdmStructuralProperty primitiveProperty = complexType.AddStructuralProperty("PrimitiveProperty", EdmCoreModel.Instance.GetString(false));
EdmStructuralProperty complexProperty = complexType.AddStructuralProperty("ComplexProperty", new EdmComplexTypeReference(complexType, false));
model.AddElement(complexType);
EdmEntityType entity = new EdmEntityType("TestNS", "EntityType");
EdmStructuralProperty entityId = entity.AddStructuralProperty("ID", EdmCoreModel.Instance.GetInt32(false));
entity.AddKeys(entityId);
EdmStructuralProperty entityComplexProperty = entity.AddStructuralProperty("ComplexProperty", new EdmComplexTypeReference(complexType, false));
model.AddElement(entity);
EdmEnumType enumType = new EdmEnumType("TestNS", "EnumType");
model.AddElement(enumType);
EdmEntityContainer container = new EdmEntityContainer("TestNS", "TestContainer");
EdmAction primitiveOperationAction = new EdmAction("TestNS", "FunctionImport_Primitive", null);
EdmOperationParameter primitiveParameter = new EdmOperationParameter(primitiveOperationAction, "primitive", EdmCoreModel.Instance.GetString(true));
primitiveOperationAction.AddParameter(primitiveParameter);
model.AddElement(primitiveOperationAction);
container.AddActionImport("FunctionImport_Primitive", primitiveOperationAction);
EdmAction primitiveCollectionOperationAction = new EdmAction("TestNS", "FunctionImport_PrimitiveCollection", null);
EdmOperationParameter primitiveCollectionParameter = new EdmOperationParameter(primitiveCollectionOperationAction, "primitiveCollection", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetString(true)));
primitiveCollectionOperationAction.AddParameter(primitiveCollectionParameter);
model.AddElement(primitiveCollectionOperationAction);
container.AddActionImport("FunctionImport_PrimitiveCollection", primitiveCollectionOperationAction);
EdmAction complexOperationAction = new EdmAction("TestNS", "FunctionImport_Complex", null);
EdmOperationParameter complexParameter = new EdmOperationParameter(complexOperationAction, "complex", new EdmComplexTypeReference(complexType, true));
complexOperationAction.AddParameter(complexParameter);
model.AddElement(complexOperationAction);
container.AddActionImport("FunctionImport_Complex", complexOperationAction);
EdmAction complexCollectionOperationAction = new EdmAction("TestNS", "FunctionImport_ComplexCollection", null);
EdmOperationParameter complexCollectionParameter = new EdmOperationParameter(complexCollectionOperationAction, "complexCollection", EdmCoreModel.GetCollection(new EdmComplexTypeReference(complexType, true)));
complexCollectionOperationAction.AddParameter(complexCollectionParameter);
model.AddElement(complexCollectionOperationAction);
container.AddActionImport("FunctionImport_ComplexCollection", complexCollectionOperationAction);
EdmAction entityOperationAction = new EdmAction("TestNS", "FunctionImport_Entry", null);
EdmOperationParameter entityParameter = new EdmOperationParameter(entityOperationAction, "entry", new EdmEntityTypeReference(entity, true));
entityOperationAction.AddParameter(entityParameter);
model.AddElement(entityOperationAction);
container.AddActionImport("FunctionImport_Entry", entityOperationAction);
EdmAction feedOperationAction = new EdmAction("TestNS", "FunctionImport_Feed", null);
EdmOperationParameter feedParameter = new EdmOperationParameter(feedOperationAction, "feed", EdmCoreModel.GetCollection(new EdmEntityTypeReference(entity, true)));
feedOperationAction.AddParameter(feedParameter);
model.AddElement(feedOperationAction);
container.AddActionImport("FunctionImport_Feed", feedOperationAction);
EdmAction streamOperationAction = new EdmAction("TestNS", "FunctionImport_Stream", null);
EdmOperationParameter streamParameter = new EdmOperationParameter(streamOperationAction, "stream", EdmCoreModel.Instance.GetStream(true));
streamOperationAction.AddParameter(streamParameter);
model.AddElement(streamOperationAction);
container.AddActionImport("FunctionImport_Stream", streamOperationAction);
EdmAction enumOperationAction = new EdmAction("TestNS", "FunctionImport_Enum", null);
EdmOperationParameter enumParameter = new EdmOperationParameter(enumOperationAction, "enum", new EdmEnumTypeReference(enumType, true));
enumOperationAction.AddParameter(enumParameter);
model.AddElement(enumOperationAction);
container.AddActionImport("FunctionImport_Enum", enumOperationAction);
model.AddElement(container);
this.BasicConstructibleModelTestSerializingStockModel(ODataTestModelBuilder.ODataTestModelWithFunctionImport, model);
}
示例9: BuildEdmModel
private void BuildEdmModel()
{
_entityType = new EdmEntityTypeReference(new EdmEntityType("NS", "Entity"), isNullable: false);
_derivedEntityType = new EdmEntityTypeReference(new EdmEntityType("NS", "DerivedEntity", _entityType.EntityDefinition()), isNullable: false);
var entityCollection = new EdmCollectionTypeReference(new EdmCollectionType(_entityType));
var derivedEntityCollection = new EdmCollectionTypeReference(new EdmCollectionType(_derivedEntityType));
EdmModel model = new EdmModel();
EdmEntityContainer container = new EdmEntityContainer("NS", "Name");
model.AddElement(container);
// non-bindable action
container.AddActionImport(new EdmAction("NS", "NonBindableAction", returnType: null));
// action bound to entity
var actionBoundToEntity = new EdmAction(
"NS",
"ActionBoundToEntity",
returnType: null,
isBound: true,
entitySetPathExpression: null);
actionBoundToEntity.AddParameter("bindingParameter", _entityType);
model.AddElement(actionBoundToEntity);
// action bound to derived entity
var actionBoundToDerivedEntity = new EdmAction(
"NS",
"ActionBoundToDerivedEntity",
returnType: null,
isBound: true,
entitySetPathExpression: null);
actionBoundToDerivedEntity.AddParameter("bindingParameter", _derivedEntityType);
model.AddElement(actionBoundToDerivedEntity);
// action bound to entity collection
var actionBoundToEntityCollection = new EdmAction(
"NS",
"ActionBoundToEntityCollection",
returnType: null,
isBound: true,
entitySetPathExpression: null);
actionBoundToEntityCollection.AddParameter("bindingParameter", entityCollection);
model.AddElement(actionBoundToEntityCollection);
// action bound to derived entity collection
var actionBoundToDerivedEntityCollection = new EdmAction(
"NS",
"ActionBoundToDerivedEntityCollection",
returnType: null,
isBound: true,
entitySetPathExpression: null);
actionBoundToDerivedEntityCollection.AddParameter("bindingParameter", derivedEntityCollection);
model.AddElement(actionBoundToDerivedEntityCollection);
// ambiguos actions
container.AddActionImport(new EdmAction("NS", "AmbiguousAction", returnType: null));
container.AddActionImport(new EdmAction("NS", "AmbiguousAction", returnType: null));
IEdmTypeReference returnType = new EdmPrimitiveTypeReference(
EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int32), false);
// non-bindable function
container.AddFunctionImport(new EdmFunction("NS", "NonBindableFunction", returnType));
// function bound to entity
var functionBoundToEntity = new EdmFunction(
"NS",
"FunctionBoundToEntity",
returnType,
isBound: true,
entitySetPathExpression: null,
isComposable: false);
functionBoundToEntity.AddParameter("bindingParameter", _entityType);
model.AddElement(functionBoundToEntity);
// function bound to entity
var functionBoundToDerivedEntity = new EdmFunction(
"NS",
"FunctionBoundToDerivedEntity",
returnType,
isBound: true,
entitySetPathExpression: null,
isComposable: false);
functionBoundToDerivedEntity.AddParameter("bindingParameter", _derivedEntityType);
model.AddElement(functionBoundToDerivedEntity);
// function bound to entity collection
var functionBoundToEntityCollection = new EdmFunction(
"NS",
"FunctionBoundToEntityCollection",
returnType,
isBound: true,
entitySetPathExpression: null,
isComposable: false);
functionBoundToEntityCollection.AddParameter("bindingParameter", entityCollection);
model.AddElement(functionBoundToEntityCollection);
// function bound to derived entity collection
var functionBoundToDerivedEntityCollection = new EdmFunction(
"NS",
//.........这里部分代码省略.........
示例10: ConstructibleModelODataTestModelBasicTest
public void ConstructibleModelODataTestModelBasicTest()
{
EdmModel model = new EdmModel();
EdmComplexType address = new EdmComplexType("TestModel", "Address");
model.AddElement(address);
EdmStructuralProperty addressStreet = address.AddStructuralProperty("Street", EdmCoreModel.Instance.GetString(true));
EdmStructuralProperty addressZip = new EdmStructuralProperty(address, "Zip", EdmCoreModel.Instance.GetInt32(false));
address.AddProperty(addressZip);
EdmEntityType office = new EdmEntityType("TestModel", "OfficeType");
EdmStructuralProperty officeId = office.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(false));
office.AddKeys(officeId);
EdmStructuralProperty officeAddress = office.AddStructuralProperty("Address", new EdmComplexTypeReference(address, false));
model.AddElement(office);
EdmEntityType city = new EdmEntityType("TestModel", "CityType");
EdmStructuralProperty cityId = city.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(false));
city.AddKeys(cityId);
EdmStructuralProperty cityName = city.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(true));
EdmStructuralProperty citySkyline = city.AddStructuralProperty("Skyline", EdmCoreModel.Instance.GetStream(false));
EdmStructuralProperty cityMetroLanes = city.AddStructuralProperty("MetroLanes", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetString(true)));
EdmNavigationProperty cityHall = city.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "CityHall", Target = office, TargetMultiplicity = EdmMultiplicity.Many });
EdmNavigationProperty dol = city.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "DOL", Target = office, TargetMultiplicity = EdmMultiplicity.Many });
EdmNavigationProperty policeStation = city.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "PoliceStation", Target = office, TargetMultiplicity = EdmMultiplicity.One });
model.AddElement(city);
EdmEntityType cityWithMap = new EdmEntityType("TestModel", "CityWithMapType", city);
model.AddElement(cityWithMap);
EdmEntityType cityOpenType = new EdmEntityType("TestModel", "CityOpenType", city, false, true);
model.AddElement(cityOpenType);
EdmEntityType person = new EdmEntityType("TestModel", "Person");
EdmStructuralProperty personId = person.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(false));
person.AddKeys(personId);
model.AddElement(person);
EdmNavigationProperty friend = person.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Friend", Target = person, TargetMultiplicity = EdmMultiplicity.Many });
EdmEntityType employee = new EdmEntityType("TestModel", "Employee", person);
EdmStructuralProperty companyName = employee.AddStructuralProperty("CompanyName", EdmCoreModel.Instance.GetString(true));
model.AddElement(employee);
EdmEntityType manager = new EdmEntityType("TestModel", "Manager", employee);
EdmStructuralProperty level = manager.AddStructuralProperty("Level", EdmCoreModel.Instance.GetInt32(false));
model.AddElement(manager);
EdmEntityContainer container = new EdmEntityContainer("TestModel", "DefaultContainer");
EdmEntitySet officeSet = new EdmEntitySet(container, "OfficeType", office);
container.AddElement(officeSet);
EdmEntitySet citySet = container.AddEntitySet("CityType", city);
EdmEntitySet personSet = container.AddEntitySet("Person", person);
citySet.AddNavigationTarget(cityHall, officeSet);
citySet.AddNavigationTarget(dol, officeSet);
citySet.AddNavigationTarget(policeStation, officeSet);
personSet.AddNavigationTarget(friend, personSet);
EdmAction serviceOperationAction = new EdmAction("TestModel", "ServiceOperation1", EdmCoreModel.Instance.GetInt32(true));
EdmOperationParameter a = new EdmOperationParameter(serviceOperationAction, "a", EdmCoreModel.Instance.GetInt32(true));
serviceOperationAction.AddParameter(a);
serviceOperationAction.AddParameter("b", EdmCoreModel.Instance.GetString(true));
model.AddElement(serviceOperationAction);
container.AddActionImport("ServiceOperation1", serviceOperationAction);
model.AddElement(container);
this.BasicConstructibleModelTestSerializingStockModel(ODataTestModelBuilder.ODataTestModelBasicTest, model);
}
示例11: GetModelWithActionWithMissingReturnSet
public static EdmModel GetModelWithActionWithMissingReturnSet()
{
EdmEntityType vegetableType = new EdmEntityType("Test", "Vegetable");
IEdmStructuralProperty id = vegetableType.AddStructuralProperty("ID", EdmCoreModel.Instance.GetInt32(false));
vegetableType.AddKeys(id);
EdmAction action = new EdmAction("Test", "ActionWithMissingReturnSet", new EdmEntityTypeReference(vegetableType, true));
// Note how the entity set expression is null even though it returns an entity
EdmEntityContainer container = new EdmEntityContainer("Test", "Container");
container.AddActionImport("ActionWithMissingReturnSet", action);
EdmModel model = new EdmModel();
model.AddElement(container);
model.AddElement(vegetableType);
model.AddElement(action);
return model;
}
示例12: GetEdmModel
//.........这里部分代码省略.........
FullyQualifiedNamespaceContextPeople.AddNavigationTarget(FullyQualifiedNamespaceEmployee_Manager, FullyQualifiedNamespaceContextPeople);
FullyQualifiedNamespaceContextPeople.AddNavigationTarget(FullyQualifiedNamespaceManager_DirectReports, FullyQualifiedNamespaceContextPeople);
FullyQualifiedNamespaceContextPeople.AddNavigationTarget(FullyQualifiedNamespacePerson_MyPet2Set, FullyQualifiedNamespaceContextPet2Set);
FullyQualifiedNamespaceContextDogs.AddNavigationTarget(FullyQualifiedNamespaceDog_MyPeople, FullyQualifiedNamespaceContextPeople);
FullyQualifiedNamespaceContextDogs.AddNavigationTarget(FullyQualifiedNamespaceDog_FastestOwner, FullyQualifiedNamespaceContextPeople);
FullyQualifiedNamespaceContextDogs.AddNavigationTarget(FullyQualifiedNamespaceDog_LionsISaw, FullyQualifiedNamespaceContextLions);
FullyQualifiedNamespaceContextLions.AddNavigationTarget(FullyQualifiedNamespaceLion_Friends, FullyQualifiedNamespaceContextLions);
FullyQualifiedNamespaceContextPaintings.AddNavigationTarget(FullyQualifiedNamespacePainting_Owner, FullyQualifiedNamespaceContextPeople);
// Add singleton
var FullQualifiedNamespaceSingletonBoss = FullyQualifiedNamespaceContext.AddSingleton("Boss", FullyQualifiedNamespacePerson);
FullQualifiedNamespaceSingletonBoss.AddNavigationTarget(FullyQualifiedNamespacePerson_MyDog, FullyQualifiedNamespaceContextDogs);
FullQualifiedNamespaceSingletonBoss.AddNavigationTarget(FullyQualifiedNamespacePerson_MyPaintings, FullyQualifiedNamespaceContextPaintings);
FullyQualifiedNamespaceContext.AddFunctionImport("GetPet1", FullyQualifiedNamespaceGetPet1Function, new EdmEntitySetReferenceExpression(FullyQualifiedNamespaceContextPet1Set));
FullyQualifiedNamespaceContext.AddFunctionImport("GetPet2", FullyQualifiedNamespaceGetPet2Function, new EdmEntitySetReferenceExpression(FullyQualifiedNamespaceContextPet2Set));
FullyQualifiedNamespaceContext.AddFunctionImport("GetPet3", FullyQualifiedNamespaceGetPet3Function, new EdmEntitySetReferenceExpression(FullyQualifiedNamespaceContextPet3Set));
FullyQualifiedNamespaceContext.AddFunctionImport("GetPet4", FullyQualifiedNamespaceGetPet4Function, new EdmEntitySetReferenceExpression(FullyQualifiedNamespaceContextPet4Set));
FullyQualifiedNamespaceContext.AddFunctionImport("GetPet5", FullyQualifiedNamespaceGetPet5Function, new EdmEntitySetReferenceExpression(FullyQualifiedNamespaceContextPet5Set));
FullyQualifiedNamespaceContext.AddFunctionImport("GetPet6", FullyQualifiedNamespaceGetPet6Function, new EdmEntitySetReferenceExpression(FullyQualifiedNamespaceContextPet6Set));
FullyQualifiedNamespaceContext.AddFunctionImport("GetPetCount", FullyQualifiedNamespaceGetPetCountFunction, new EdmEntitySetReferenceExpression(FullyQualifiedNamespaceContextPet5Set));
FullyQualifiedNamespaceContext.AddFunctionImport("FindMyOwner", FullyQualifiedNamespaceFindMyOwnerFunction, new EdmEntitySetReferenceExpression(model.FindEntityContainer("Fully.Qualified.Namespace.Context").FindEntitySet("People")));
FullyQualifiedNamespaceContext.AddFunctionImport("IsAddressGood", FullyQualifiedNamespaceIsAddressGoodFunction, null);
FullyQualifiedNamespaceContext.AddFunctionImport("GetCoolPeople", FullyQualifiedNamespaceGetCoolPeopleAction, new EdmEntitySetReferenceExpression(model.FindEntityContainer("Fully.Qualified.Namespace.Context").FindEntitySet("People")));
FullyQualifiedNamespaceContext.AddFunctionImport("GetCoolestPerson", FullyQualifiedNamespaceGetCoolestPersonAction, new EdmEntitySetReferenceExpression(model.FindEntityContainer("Fully.Qualified.Namespace.Context").FindEntitySet("People")));
FullyQualifiedNamespaceContext.AddFunctionImport("GetCoolestPersonWithStyle", FullyQualifiedNamespaceGetCoolestPersonWithStyleAction, new EdmEntitySetReferenceExpression(model.FindEntityContainer("Fully.Qualified.Namespace.Context").FindEntitySet("People")));
FullyQualifiedNamespaceContext.AddFunctionImport("GetBestManager", FullyQualifiedNamespaceGetBestManagerAction, new EdmEntitySetReferenceExpression(model.FindEntityContainer("Fully.Qualified.Namespace.Context").FindEntitySet("People")));
FullyQualifiedNamespaceContext.AddActionImport("GetNothing", FullyQualifiedNamespaceGetNothingAction);
FullyQualifiedNamespaceContext.AddFunctionImport("GetSomeNumber", FullyQualifiedNamespaceGetSomeNumberAction);
FullyQualifiedNamespaceContext.AddFunctionImport("GetSomeAddress", FullyQualifiedNamespaceGetSomeAddressAction);
FullyQualifiedNamespaceContext.AddFunctionImport("GetSomeNumbers", FullyQualifiedNamespaceGetSomeNumbersAction);
FullyQualifiedNamespaceContext.AddFunctionImport("GetSomeAddresses", FullyQualifiedNamespaceGetSomeAddressesAction);
FullyQualifiedNamespaceContext.AddActionImport("ResetAllData", FullyQualifiedNamespaceResetAllDataAction);
FullyQualifiedNamespaceContext.AddFunctionImport("GetMostImporantPerson", FullyQualifiedNamespaceGetMostImporantPersonFunction);
FullyQualifiedNamespaceContext.AddFunctionImport("GetMostImporantPerson", FullyQualifiedNamespaceGetMostImporantPersonFunction2);
FullyQualifiedNamespaceContext.AddActionImport("MoveEveryone", FullyQualifiedNamespaceMoveEveryoneAction);
#endregion
try
{
// serialize edm
XDocument document = new XDocument();
IEnumerable<EdmError> errors;
using (var writer = document.CreateWriter())
{
EdmxWriter.TryWriteEdmx(model, writer, EdmxTarget.OData, out errors).Should().BeTrue();
}
string doc = document.ToString();
// deserialize edm xml
示例13: AddUnboundAction
private static IEdmActionImport AddUnboundAction(EdmEntityContainer container, string name, IEdmEntityType bindingType, bool isCollection)
{
var action = new EdmAction(
container.Namespace, name, returnType: null, isBound: true, entitySetPathExpression: null);
IEdmTypeReference bindingParamterType = new EdmEntityTypeReference(bindingType, isNullable: false);
if (isCollection)
{
bindingParamterType = new EdmCollectionTypeReference(new EdmCollectionType(bindingParamterType));
}
action.AddParameter("bindingParameter", bindingParamterType);
var actionImport = container.AddActionImport(action);
return actionImport;
}
示例14: CreateODataServiceModel
public static IEdmModel CreateODataServiceModel(string ns)
{
EdmModel model = new EdmModel();
var defaultContainer = new EdmEntityContainer(ns, "OperationService");
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);
#endregion
#region EnumType
var customerLevelType = new EdmEnumType(ns, "CustomerLevel");
customerLevelType.AddMember("Common", new EdmIntegerConstant(0));
customerLevelType.AddMember("Silver", new EdmIntegerConstant(1));
customerLevelType.AddMember("Gold", new EdmIntegerConstant(2));
model.AddElement(customerLevelType);
#endregion
#region EntityType
var customerType = new EdmEntityType(ns, "Customer");
var customerIdProperty = new EdmStructuralProperty(customerType, "ID", EdmCoreModel.Instance.GetInt32(false));
customerType.AddProperty(customerIdProperty);
customerType.AddKeys(customerIdProperty);
customerType.AddStructuralProperty("FirstName", EdmCoreModel.Instance.GetString(false));
customerType.AddStructuralProperty("LastName", EdmCoreModel.Instance.GetString(false));
customerType.AddStructuralProperty("Address", new EdmComplexTypeReference(addressType, true));
customerType.AddStructuralProperty("Emails", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(true))));
customerType.AddStructuralProperty("Level", new EdmEnumTypeReference(customerLevelType, false));
model.AddElement(customerType);
var orderType = new EdmEntityType(ns, "Order");
var orderIdProperty = new EdmStructuralProperty(orderType, "ID", EdmCoreModel.Instance.GetInt32(false));
orderType.AddProperty(orderIdProperty);
orderType.AddKeys(orderIdProperty);
orderType.AddStructuralProperty("OrderDate", EdmCoreModel.Instance.GetDateTimeOffset(false));
orderType.AddStructuralProperty("Notes", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(true))));
model.AddElement(orderType);
var ordersNavigation = customerType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
{
Name = "Orders",
Target = orderType,
TargetMultiplicity = EdmMultiplicity.Many
});
var customerForOrderNavigation = orderType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
{
Name = "Customer",
Target = customerType,
TargetMultiplicity = EdmMultiplicity.One
});
#endregion
#region EntitySet
var customerSet = new EdmEntitySet(defaultContainer, "Customers", customerType);
defaultContainer.AddElement(customerSet);
var orderSet = new EdmEntitySet(defaultContainer, "Orders", orderType);
defaultContainer.AddElement(orderSet);
customerSet.AddNavigationTarget(ordersNavigation, orderSet);
orderSet.AddNavigationTarget(customerForOrderNavigation, customerSet);
#endregion
#region Operations
//UnBound Action: ResetDataSource
var resetDataSourceAction = new EdmAction(ns, "ResetDataSource", null, false, null);
model.AddElement(resetDataSourceAction);
defaultContainer.AddActionImport(resetDataSourceAction);
var customerTypeReference = new EdmEntityTypeReference(customerType, true);
var customerCollectionTypeReference =
new EdmCollectionTypeReference(new EdmCollectionType(customerTypeReference));
var addressTypeReference = new EdmComplexTypeReference(addressType, true);
var addressCollectionTypeRefernce =
new EdmCollectionTypeReference(new EdmCollectionType(addressTypeReference));
var stringTypeReference = EdmCoreModel.Instance.GetString(true);
var stringCollectionTypeReference =
new EdmCollectionTypeReference(new EdmCollectionType(stringTypeReference));
//.........这里部分代码省略.........
示例15: OperationImportNameSimpleIdentifier
public static IEdmModel OperationImportNameSimpleIdentifier()
{
var model = new EdmModel();
var container = new EdmEntityContainer("Default", "Container");
var function1 = new EdmFunction("Default", "Function1", EdmCoreModel.Instance.GetInt32(false));
var function2 = new EdmFunction("Default", "Function2", EdmCoreModel.Instance.GetInt32(false));
var function3 = new EdmFunction("Default", "Function3", EdmCoreModel.Instance.GetInt32(false));
var function4 = new EdmFunction("Default", "Function4", EdmCoreModel.Instance.GetInt32(false));
container.AddFunctionImport("ValidName", function1);
container.AddFunctionImport("[email protected]#$%^&*()", function2);
container.AddFunctionImport(" ", function3);
container.AddFunctionImport(string.Empty, function4);
var action1 = new EdmAction("Default", "Action1", EdmCoreModel.Instance.GetInt32(false));
var action2 = new EdmAction("Default", "Action2", EdmCoreModel.Instance.GetInt32(false));
model.AddElement(action1);
model.AddElement(action2);
container.AddActionImport(new string('F', 480), action1);
container.AddActionImport(new string('F', 481), action2);
model.AddElement(container);
model.AddElement(function1);
model.AddElement(function2);
model.AddElement(function3);
model.AddElement(function4);
return model;
}