本文整理汇总了C#中Microsoft.OData.Edm.Library.EdmComplexType.ToEdmTypeReference方法的典型用法代码示例。如果您正苦于以下问题:C# EdmComplexType.ToEdmTypeReference方法的具体用法?C# EdmComplexType.ToEdmTypeReference怎么用?C# EdmComplexType.ToEdmTypeReference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.OData.Edm.Library.EdmComplexType
的用法示例。
在下文中一共展示了EdmComplexType.ToEdmTypeReference方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCustomers
private static EdmEntityObjectCollection GetCustomers()
{
if (_untypedSimpleOpenCustormers != null)
{
return _untypedSimpleOpenCustormers;
}
EdmEntityType customerType = new EdmEntityType("NS", "UntypedSimpleOpenCustomer", null, false, true);
customerType.AddKeys(customerType.AddStructuralProperty("CustomerId", EdmPrimitiveTypeKind.Int32));
EdmEntityObject customer = new EdmEntityObject(customerType);
customer.TrySetPropertyValue("CustomerId", 1);
//Add Numbers primitive collection property
customer.TrySetPropertyValue("DeclaredNumbers", new[] { 1, 2 });
//Add Color, Colors enum(collection) property
EdmEnumType colorType = new EdmEnumType("NS", "Color");
colorType.AddMember(new EdmEnumMember(colorType, "Red", new EdmIntegerConstant(0)));
EdmEnumObject color = new EdmEnumObject(colorType, "Red");
EdmEnumObject color2 = new EdmEnumObject(colorType, "0");
EdmEnumObject color3 = new EdmEnumObject(colorType, "Red");
customer.TrySetPropertyValue("Color", color);
List<IEdmEnumObject> colorList = new List<IEdmEnumObject>();
colorList.Add(color);
colorList.Add(color2);
colorList.Add(color3);
IEdmCollectionTypeReference enumCollectionType = new EdmCollectionTypeReference(new EdmCollectionType(colorType.ToEdmTypeReference(false)));
EdmEnumObjectCollection colors = new EdmEnumObjectCollection(enumCollectionType, colorList);
customer.TrySetPropertyValue("Colors", colors);
customer.TrySetPropertyValue("DeclaredColors", colors);
//Add Addresses complex(collection) property
EdmComplexType addressType = new EdmComplexType("NS", "Address", null, false, true);
addressType.AddStructuralProperty("Street", EdmPrimitiveTypeKind.String);
EdmComplexObject address = new EdmComplexObject(addressType);
address.TrySetPropertyValue("Street", "No1");
EdmComplexObject address2 = new EdmComplexObject(addressType);
address2.TrySetPropertyValue("Street", "No2");
List<IEdmComplexObject> addressList = new List<IEdmComplexObject>();
addressList.Add(address);
addressList.Add(address2);
IEdmCollectionTypeReference complexCollectionType = new EdmCollectionTypeReference(new EdmCollectionType(addressType.ToEdmTypeReference(false)));
EdmComplexObjectCollection addresses = new EdmComplexObjectCollection(complexCollectionType, addressList);
customer.TrySetPropertyValue("DeclaredAddresses", addresses);
EdmEntityObjectCollection customers = new EdmEntityObjectCollection(new EdmCollectionTypeReference(new EdmCollectionType(customerType.ToEdmTypeReference(false))));
customers.Add(customer);
_untypedSimpleOpenCustormers = customers;
return _untypedSimpleOpenCustormers;
}
示例2: SimpleOpenTypeModel
public static IEdmModel SimpleOpenTypeModel()
{
var model = new EdmModel();
// Address is an open complex type
var addressType = new EdmComplexType("Default", "Address", null, false, true);
addressType.AddStructuralProperty("Street", EdmPrimitiveTypeKind.String);
addressType.AddStructuralProperty("City", EdmPrimitiveTypeKind.String);
model.AddElement(addressType);
// ZipCode is an open complex type also
var zipCodeType = new EdmComplexType("Default", "ZipCode", null, false, true);
zipCodeType.AddStructuralProperty("Code", EdmPrimitiveTypeKind.Int32);
model.AddElement(zipCodeType);
// Enum type simpleEnum
EdmEnumType simpleEnum = new EdmEnumType("Default", "SimpleEnum");
simpleEnum.AddMember(new EdmEnumMember(simpleEnum, "First", new EdmIntegerConstant(0)));
simpleEnum.AddMember(new EdmEnumMember(simpleEnum, "Second", new EdmIntegerConstant(1)));
simpleEnum.AddMember(new EdmEnumMember(simpleEnum, "Third", new EdmIntegerConstant(2)));
simpleEnum.AddMember(new EdmEnumMember(simpleEnum, "Fourth", new EdmIntegerConstant(3)));
model.AddElement(simpleEnum);
// Customer is an open entity type
var customerType = new EdmEntityType("Default", "Customer", null, false, true);
customerType.AddKeys(customerType.AddStructuralProperty("CustomerId", EdmPrimitiveTypeKind.Int32));
customerType.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
customerType.AddStructuralProperty("Address", addressType.ToEdmTypeReference(false));
model.AddElement(customerType);
var container = new EdmEntityContainer("Default", "Container");
model.AddElement(container);
var customers = new EdmEntitySet(container, "Customers", customerType);
container.AddElement(customers);
return model;
}
示例3: GetUntypedEdmModel
private static IEdmModel GetUntypedEdmModel()
{
var model = new EdmModel();
// complex type address
EdmComplexType address = new EdmComplexType("NS", "Address", null, false, true);
address.AddStructuralProperty("Street", EdmPrimitiveTypeKind.String);
model.AddElement(address);
IEdmCollectionTypeReference complexCollectionType = new EdmCollectionTypeReference(new EdmCollectionType(address.ToEdmTypeReference(false)));
// enum type color
EdmEnumType color = new EdmEnumType("NS", "Color");
color.AddMember(new EdmEnumMember(color, "Red", new EdmIntegerConstant(0)));
model.AddElement(color);
IEdmCollectionTypeReference enumCollectionType = new EdmCollectionTypeReference(new EdmCollectionType(color.ToEdmTypeReference(false)));
// primitive collection type
IEdmTypeReference intType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int32, isNullable: true);
EdmCollectionTypeReference primitiveCollectionType = new EdmCollectionTypeReference(new EdmCollectionType(intType));
// entity type customer
EdmEntityType customer = new EdmEntityType("NS", "UntypedSimpleOpenCustomer", null, false, true);
customer.AddKeys(customer.AddStructuralProperty("CustomerId", EdmPrimitiveTypeKind.Int32));
customer.AddStructuralProperty("Color", new EdmEnumTypeReference(color, isNullable: true));
customer.AddStructuralProperty("DeclaredAddresses", complexCollectionType);
customer.AddStructuralProperty("DeclaredColors", enumCollectionType);
customer.AddStructuralProperty("DeclaredNumbers", primitiveCollectionType);
model.AddElement(customer);
EdmAction action = new EdmAction(
"NS",
"AddColor",
null,
isBound: true,
entitySetPathExpression: null);
action.AddParameter("bindingParameter", new EdmEntityTypeReference(customer, false));
action.AddParameter("Color", new EdmEnumTypeReference(color, true));
model.AddElement(action);
EdmEntityContainer container = new EdmEntityContainer("NS", "Container");
container.AddEntitySet("UntypedSimpleOpenCustomers", customer);
model.AddElement(container);
return model;
}