本文整理汇总了C#中Microsoft.OData.Edm.Library.EdmFunction.AddParameter方法的典型用法代码示例。如果您正苦于以下问题:C# EdmFunction.AddParameter方法的具体用法?C# EdmFunction.AddParameter怎么用?C# EdmFunction.AddParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.OData.Edm.Library.EdmFunction
的用法示例。
在下文中一共展示了EdmFunction.AddParameter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetEdmModel
private IEdmModel GetEdmModel()
{
EdmModel model = new EdmModel();
EdmEntityContainer container = new EdmEntityContainer("NS", "Name");
model.AddElement(container);
IEdmTypeReference returnType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false);
IEdmTypeReference parameterType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false);
container.AddFunctionImport(new EdmFunction("NS", "FunctionWithoutParams", returnType));
var functionWithOneParam = new EdmFunction("NS", "FunctionWithOneParam", returnType);
functionWithOneParam.AddParameter("Parameter", parameterType);
container.AddFunctionImport(functionWithOneParam);
var functionWithMultipleParams = new EdmFunction("NS", "FunctionWithMultipleParams", returnType);
functionWithMultipleParams.AddParameter("Parameter1", parameterType);
functionWithMultipleParams.AddParameter("Parameter2", parameterType);
functionWithMultipleParams.AddParameter("Parameter3", parameterType);
container.AddFunctionImport(functionWithMultipleParams);
container.AddFunctionImport(new EdmFunction("NS", "FunctionWithOverloads", returnType));
var functionWithOverloads2 = new EdmFunction("NS", "FunctionWithOverloads", returnType);
functionWithOverloads2.AddParameter("Parameter", parameterType);
container.AddFunctionImport(functionWithOverloads2);
var functionWithOverloads3 = new EdmFunction("NS", "FunctionWithOverloads", returnType);
functionWithOverloads3.AddParameter("Parameter1", parameterType);
functionWithOverloads3.AddParameter("Parameter2", parameterType);
functionWithOverloads3.AddParameter("Parameter3", parameterType);
container.AddFunctionImport(functionWithOverloads3);
return model;
}
示例2: EdmFunction
public void DuplicateFunctionsUnBoundFunctionsWithSameNameWhereBindingTypeDifferentonNullabilityAndSameParametersShouldError()
{
var edmFunction = new EdmFunction("n.s", "GetStuff", EdmCoreModel.Instance.GetString(true), true /*isBound*/, null /*entitySetPath*/, false /*isComposable*/);
edmFunction.AddParameter("bindingParameter", EdmCoreModel.Instance.GetInt16(true));
edmFunction.AddParameter("differentName", EdmCoreModel.Instance.GetInt16(true));
var edmFunction2 = new EdmFunction("n.s", "GetStuff", EdmCoreModel.Instance.GetString(true), true /*isBound*/, null /*entitySetPath*/, false /*isComposable*/);
edmFunction2.AddParameter("bindingParameter", EdmCoreModel.Instance.GetInt16(true));
edmFunction2.AddParameter("otherParameter", EdmCoreModel.Instance.GetInt16(false));
EdmModel model = new EdmModel();
model.AddElement(edmFunction);
model.AddElement(edmFunction2);
ValidateError(model, EdmErrorCode.DuplicateFunctions, Strings.EdmModel_Validator_Semantic_ModelDuplicateBoundFunctionParameterTypes("n.s.GetStuff"));
}
示例3: DuplicateBoundFunctionOverloadsSameParameterNamesShouldError
public void DuplicateBoundFunctionOverloadsSameParameterNamesShouldError()
{
var edmFunction = new EdmFunction("n.s", "GetStuff", EdmCoreModel.Instance.GetString(true), true /*isBound*/, null /*entitySetPath*/, false /*isComposable*/);
edmFunction.AddParameter("bindingParameter", EdmCoreModel.Instance.GetInt32(true));
edmFunction.AddParameter("param1", EdmCoreModel.Instance.GetInt32(true));
var edmFunction2 = new EdmFunction("n.s", "GetStuff", EdmCoreModel.Instance.GetInt16(true), true /*isBound*/, null /*entitySetPath*/, false /*isComposable*/);
edmFunction2.AddParameter("bindingParameter", EdmCoreModel.Instance.GetInt32(true));
edmFunction2.AddParameter("param1", EdmCoreModel.Instance.GetInt16(true));
EdmModel model = new EdmModel();
model.AddElement(edmFunction);
model.AddElement(edmFunction2);
ValidateError(model, EdmErrorCode.DuplicateFunctions, Strings.EdmModel_Validator_Semantic_ModelDuplicateBoundFunctionParameterNames("n.s.GetStuff"));
}
示例4: MultipleSchemasWithDifferentNamespacesEdm
public static IEdmModel MultipleSchemasWithDifferentNamespacesEdm()
{
var namespaces = new string[]
{
"FindMethodsTestModelBuilder.MultipleSchemasWithDifferentNamespaces.first",
"FindMethodsTestModelBuilder.MultipleSchemasWithDifferentNamespaces.second"
};
var model = new EdmModel();
foreach (var namespaceName in namespaces)
{
var entityType1 = new EdmEntityType(namespaceName, "validEntityType1");
entityType1.AddKeys(entityType1.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
var entityType2 = new EdmEntityType(namespaceName, "VALIDeNTITYtYPE2");
entityType2.AddKeys(entityType2.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
var entityType3 = new EdmEntityType(namespaceName, "VALIDeNTITYtYPE3");
entityType3.AddKeys(entityType3.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
entityType1.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo {Name = "Mumble", Target = entityType2, TargetMultiplicity = EdmMultiplicity.Many});
var complexType = new EdmComplexType(namespaceName, "ValidNameComplexType1");
complexType.AddStructuralProperty("aPropertyOne", new EdmComplexTypeReference(complexType, false));
model.AddElements(new IEdmSchemaElement[] { entityType1, entityType2, entityType3, complexType });
var function1 = new EdmFunction(namespaceName, "ValidFunction1", EdmCoreModel.Instance.GetSingle(false));
var function2 = new EdmFunction(namespaceName, "ValidFunction1", EdmCoreModel.Instance.GetSingle(false));
function2.AddParameter("param1", new EdmEntityTypeReference(entityType1, false));
var function3 = new EdmFunction(namespaceName, "ValidFunction1", EdmCoreModel.Instance.GetSingle(false));
function3.AddParameter("param1", EdmCoreModel.Instance.GetSingle(false));
model.AddElements(new IEdmSchemaElement[] {function1, function2, function3});
}
return model;
}
示例5: FunctionImportShouldProduceCorrectFullyQualifiedNameAndNotHaveParameters
public void FunctionImportShouldProduceCorrectFullyQualifiedNameAndNotHaveParameters()
{
var function = new EdmFunction("d.s", "testFunction", EdmCoreModel.Instance.GetString(true));
function.AddParameter("param1", EdmCoreModel.Instance.GetString(false));
var functionImport = new EdmFunctionImport(new EdmEntityContainer("d.s", "container"), "testFunction", function);
EdmUtil.FullyQualifiedName(functionImport).Should().Be("d.s.container/testFunction");
}
示例6: TryMatch_ReturnTrue_IfSameUnboundFunction
public void TryMatch_ReturnTrue_IfSameUnboundFunction()
{
// Arrange
IEdmModel model = new Mock<IEdmModel>().Object;
IEdmEntityType returnType = new Mock<IEdmEntityType>().Object;
EdmEntityContainer container = new EdmEntityContainer("NS", "Container");
EdmFunction func = new EdmFunction("NS", "Function", new EdmEntityTypeReference(returnType, isNullable: false));
func.AddParameter("Parameter1", EdmCoreModel.Instance.GetInt32(isNullable: false));
func.AddParameter("Parameter2", EdmCoreModel.Instance.GetInt32(isNullable: false));
EdmFunctionImport function = new EdmFunctionImport(container, "Function", func);
Dictionary<string, string> parameterValues = new Dictionary<string, string>
{
{ "Parameter1", "1" },
{ "Parameter2", "2" }
};
Dictionary<string, string> parameterMappings = new Dictionary<string, string>
{
{ "Parameter1", "{param1}" },
{ "Parameter2", "{param2}" }
};
UnboundFunctionPathSegment segment = new UnboundFunctionPathSegment(function, model, parameterValues);
UnboundFunctionPathSegmentTemplate template = new UnboundFunctionPathSegmentTemplate(
new UnboundFunctionPathSegment(function, model, parameterMappings));
// Act
Dictionary<string, object> values = new Dictionary<string,object>();
bool result = template.TryMatch(segment, values);
// Assert
Assert.True(result);
Assert.Equal(4, values.Count);
Assert.Equal("1", values["param1"]);
Assert.Equal("2", values["param2"]);
Assert.Equal(1, (values[ODataParameterValue.ParameterValuePrefix + "param1"] as ODataParameterValue).Value);
Assert.Equal(2, (values[ODataParameterValue.ParameterValuePrefix + "param2"] as ODataParameterValue).Value);
}
示例7: DuplicateFunctionOverloadsWithDifferentBindingTypesAndSameNameWithDifferentReturnTypesShouldNotError
public void DuplicateFunctionOverloadsWithDifferentBindingTypesAndSameNameWithDifferentReturnTypesShouldNotError()
{
var edmFunction = new EdmFunction("n.s", "GetStuff", EdmCoreModel.Instance.GetString(true), true /*isBound*/, null /*entitySetPath*/, false /*isComposable*/);
edmFunction.AddParameter("bindingParameter", EdmCoreModel.Instance.GetInt16(true));
var edmFunction2 = new EdmFunction("n.s", "GetStuff", EdmCoreModel.Instance.GetInt16(true), true /*isBound*/, null /*entitySetPath*/, false /*isComposable*/);
edmFunction2.AddParameter("bindingParameter", EdmCoreModel.Instance.GetInt32(true));
EdmModel model = new EdmModel();
model.AddElement(edmFunction);
model.AddElement(edmFunction2);
ValidateNoError(model);
}
示例8: EdmFunctionConstructorShouldHaveSpecifiedConstructorValues
public void EdmFunctionConstructorShouldHaveSpecifiedConstructorValues()
{
var entitySetPath = new EdmPathExpression("Param1/Nav");
var edmFunction = new EdmFunction(defaultNamespaceName, checkout, this.boolType, true, entitySetPath, true /*IsComposable*/);
edmFunction.AddParameter(new EdmOperationParameter(edmFunction, "Param1", new EdmEntityTypeReference(personType, false)));
edmFunction.Namespace.Should().Be(defaultNamespaceName);
edmFunction.Name.Should().Be(checkout);
edmFunction.ReturnType.Should().Be(this.boolType);
edmFunction.EntitySetPath.Should().Be(entitySetPath);
edmFunction.IsBound.Should().BeTrue();
edmFunction.SchemaElementKind.Should().Be(EdmSchemaElementKind.Function);
edmFunction.IsComposable.Should().BeTrue();
}
示例9: 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;
}
示例10: CanParse_FunctionParameters_CanResolveAliasedParameterValue
public void CanParse_FunctionParameters_CanResolveAliasedParameterValue()
{
// Arrange
var model = new CustomersModelWithInheritance();
IEdmTypeReference returnType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false);
var function = new EdmFunction(
model.Container.Namespace,
"FunctionAtRoot",
returnType,
isBound: false,
entitySetPathExpression: null,
isComposable: true);
function.AddParameter("IntParameter", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int32, isNullable: false));
model.Container.AddFunctionImport("FunctionAtRoot", function, entitySet: null);
// Act
ODataPath path = _parser.Parse(model.Model, "FunctionAtRoot([email protected])");
UnboundFunctionPathSegment functionSegment = (UnboundFunctionPathSegment)path.Segments.Last();
// Assert
UnresolvedParameterValue unresolvedParamValue = functionSegment.GetParameterValue("IntParameter") as UnresolvedParameterValue;
int intParameter = (int)unresolvedParamValue.Resolve(new Uri("http://services.odata.org/FunctionAtRoot([email protected])[email protected]=1"));
Assert.Equal(1, intParameter);
}
示例11: AddFunction
private static EdmFunction AddFunction(CustomersModelWithInheritance model, string name,
IEdmTypeReference returnType = null, IEdmEntitySet entitySet = null, IEdmTypeReference bindingParameterType = null)
{
returnType = returnType ?? EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false);
IEdmExpression expression = entitySet == null ? null : new EdmEntitySetReferenceExpression(entitySet);
var function = new EdmFunction(
model.Container.Namespace,
name,
returnType,
isBound: bindingParameterType != null,
entitySetPathExpression: null,
isComposable: true);
if (bindingParameterType != null)
{
function.AddParameter("bindingParameter", bindingParameterType);
model.Model.AddElement(function);
}
else
{
model.Container.AddFunctionImport(name, function, expression);
}
return function;
}
示例12: ModelWithAllConceptsEdm
public static IEdmModel ModelWithAllConceptsEdm()
{
var stringType = EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.String);
var model = new EdmModel();
var addressType = new EdmComplexType("NS1", "Address");
addressType.AddStructuralProperty("Street", EdmPrimitiveTypeKind.String);
addressType.AddStructuralProperty("City", new EdmStringTypeReference(stringType, /*isNullable*/false, /*isUnbounded*/false, /*maxLength*/30, /*isUnicode*/true));
model.AddElement(addressType);
var zipCodeType = new EdmComplexType("NS1", "ZipCode");
zipCodeType.AddStructuralProperty("Main", new EdmStringTypeReference(stringType, /*isNullable*/false, /*isUnbounded*/false, /*maxLength*/5, /*isUnicode*/false));
zipCodeType.AddStructuralProperty("Extended", new EdmStringTypeReference(stringType, /*isNullable*/true, /*isUnbounded*/false, /*maxLength*/5, /*isUnicode*/false));
model.AddElement(zipCodeType);
addressType.AddStructuralProperty("Zip", new EdmComplexTypeReference(zipCodeType, false));
var foreignAddressType = new EdmComplexType("NS1", "ForeignAddress", addressType, false);
foreignAddressType.AddStructuralProperty("State", EdmPrimitiveTypeKind.String);
model.AddElement(foreignAddressType);
var personType = new EdmEntityType("NS1", "Person", null, true, false);
personType.AddKeys(personType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32, false));
model.AddElement(personType);
var customerType = new EdmEntityType("NS1", "Customer", personType);
customerType.AddStructuralProperty("IsVIP", EdmPrimitiveTypeKind.Boolean);
customerType.AddProperty(new EdmStructuralProperty(customerType, "LastUpdated", EdmCoreModel.Instance.GetDateTimeOffset(false), null, EdmConcurrencyMode.Fixed));
customerType.AddStructuralProperty("BillingAddress", new EdmComplexTypeReference(addressType, false));
customerType.AddStructuralProperty("ShippingAddress", new EdmComplexTypeReference(addressType, false));
model.AddElement(customerType);
var orderType = new EdmEntityType("NS1", "Order");
orderType.AddKeys(orderType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32, false));
var customerIdProperty = orderType.AddStructuralProperty("CustomerId", EdmPrimitiveTypeKind.Int32, false);
model.AddElement(orderType);
var navProp1 = new EdmNavigationPropertyInfo { Name = "ToOrders", Target = orderType, TargetMultiplicity = EdmMultiplicity.Many, };
var navProp2 = new EdmNavigationPropertyInfo { Name = "ToCustomer", Target = customerType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { customerIdProperty }, PrincipalProperties = customerType.Key() };
customerType.AddBidirectionalNavigation(navProp1, navProp2);
var container = new EdmEntityContainer("NS1", "MyContainer");
container.AddEntitySet("PersonSet", personType);
container.AddEntitySet("OrderSet", orderType);
model.AddElement(container);
var function = new EdmFunction("NS1", "Function1", EdmCoreModel.Instance.GetInt64(true));
function.AddParameter("Param1", EdmCoreModel.Instance.GetInt32(true));
container.AddFunctionImport(function);
model.AddElement(function);
return model;
}
示例13: EntityContainerWithOperationImportsEdm
public static IEdmModel EntityContainerWithOperationImportsEdm()
{
var model = new EdmModel();
var customerType = new EdmEntityType("NS1", "Customer");
customerType.AddKeys(customerType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
model.AddElement(customerType);
var container = new EdmEntityContainer("NS1", "MyContainer");
var customerSet = container.AddEntitySet("Customer", customerType);
var function = new EdmFunction("NS1", "GetCustomersExcluding", EdmCoreModel.GetCollection(new EdmEntityTypeReference(customerType, false)), false, null, false);
function.AddParameter("CustomerId", EdmCoreModel.Instance.GetInt32(true));
model.AddElement(function);
container.AddFunctionImport("GetCustomersExcluding", function, new EdmEntitySetReferenceExpression(customerSet));
model.AddElement(container);
return model;
}
示例14: CannotParseOverloadUnboundFunctionWithDifferentParamterType
public void CannotParseOverloadUnboundFunctionWithDifferentParamterType(string uri)
{
// Arrange
EdmModel model = new EdmModel();
EdmEntityContainer container = new EdmEntityContainer("NS", "Container");
model.AddElement(container);
var unboundFunction = new EdmFunction("NS", "OverloadUnboundFunction", EdmCoreModel.Instance.GetInt32(false));
unboundFunction.AddParameter("Parameter", EdmCoreModel.Instance.GetInt32(false));
model.AddElement(unboundFunction);
unboundFunction = new EdmFunction("NS", "OverloadUnboundFunction", EdmCoreModel.Instance.GetInt32(false));
unboundFunction.AddParameter("Parameter", EdmCoreModel.Instance.GetString(false));
model.AddElement(unboundFunction);
// Act & Assert
Assert.Throws<ODataUnrecognizedPathException>(
() => _parser.Parse(model, _serviceRoot, _serviceRoot + uri),
"Resource not found for the segment 'OverloadUnboundFunction'.");
}
示例15: GetParameterValue
private object GetParameterValue(object value, Type type)
{
var model = new CustomersModelWithInheritance();
IEdmTypeReference returnType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false);
var function = new EdmFunction(
model.Container.Namespace,
"FunctionAtRoot",
returnType,
isBound: false,
entitySetPathExpression: null,
isComposable: true);
model.Model.SetAnnotationValue(model.Model.FindType("NS.SimpleEnum"), new ClrTypeAnnotation(typeof(SimpleEnum)));
function.AddParameter("Parameter", model.Model.GetEdmTypeReference(type));
model.Container.AddFunctionImport("FunctionAtRoot", function, entitySet: null);
ODataPath path = _parser.Parse(
model.Model,
_serviceRoot,
"FunctionAtRoot(Parameter=" + ODataUriUtils.ConvertToUriLiteral(value, ODataVersion.V4) + ")");
UnboundFunctionPathSegment functionSegment = (UnboundFunctionPathSegment)path.Segments.Last();
return functionSegment.GetParameterValue("Parameter");
}