本文整理汇总了C#中Microsoft.OData.Edm.Library.EdmEntityType.AddProperty方法的典型用法代码示例。如果您正苦于以下问题:C# EdmEntityType.AddProperty方法的具体用法?C# EdmEntityType.AddProperty怎么用?C# EdmEntityType.AddProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.OData.Edm.Library.EdmEntityType
的用法示例。
在下文中一共展示了EdmEntityType.AddProperty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NonPrimitiveTypeRoundtripAtomTests
public NonPrimitiveTypeRoundtripAtomTests()
{
this.model = new EdmModel();
EdmComplexType personalInfo = new EdmComplexType(MyNameSpace, "PersonalInfo");
personalInfo.AddStructuralProperty("Age", EdmPrimitiveTypeKind.Int16);
personalInfo.AddStructuralProperty("Email", EdmPrimitiveTypeKind.String);
personalInfo.AddStructuralProperty("Tel", EdmPrimitiveTypeKind.String);
personalInfo.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Guid);
EdmComplexType subjectInfo = new EdmComplexType(MyNameSpace, "Subject");
subjectInfo.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
subjectInfo.AddStructuralProperty("Score", EdmPrimitiveTypeKind.Int16);
EdmCollectionTypeReference subjectsCollection = new EdmCollectionTypeReference(new EdmCollectionType(new EdmComplexTypeReference(subjectInfo, isNullable:true)));
EdmEntityType studentInfo = new EdmEntityType(MyNameSpace, "Student");
studentInfo.AddStructuralProperty("Info", new EdmComplexTypeReference(personalInfo, isNullable: false));
studentInfo.AddProperty(new EdmStructuralProperty(studentInfo, "Subjects", subjectsCollection));
EdmCollectionTypeReference hobbiesCollection = new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(isNullable: false)));
studentInfo.AddProperty(new EdmStructuralProperty(studentInfo, "Hobbies", hobbiesCollection));
model.AddElement(studentInfo);
model.AddElement(personalInfo);
model.AddElement(subjectInfo);
}
示例2: 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;
}
示例3: Initialize
public void Initialize()
{
this.model = new EdmModel();
EdmComplexType personalInfo = new EdmComplexType(MyNameSpace, "PersonalInfo");
personalInfo.AddStructuralProperty("Age", EdmPrimitiveTypeKind.Int16);
personalInfo.AddStructuralProperty("Email", EdmPrimitiveTypeKind.String);
personalInfo.AddStructuralProperty("Tel", EdmPrimitiveTypeKind.String);
personalInfo.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Guid);
EdmComplexType derivedPersonalInfo = new EdmComplexType(MyNameSpace, "DerivedPersonalInfo", personalInfo);
derivedPersonalInfo.AddStructuralProperty("Hobby", EdmPrimitiveTypeKind.String);
EdmComplexType derivedDerivedPersonalInfo = new EdmComplexType(MyNameSpace, "DerivedDerivedPersonalInfo", derivedPersonalInfo);
derivedDerivedPersonalInfo.AddStructuralProperty("Education", EdmPrimitiveTypeKind.String);
EdmComplexType subjectInfo = new EdmComplexType(MyNameSpace, "Subject");
subjectInfo.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
subjectInfo.AddStructuralProperty("Score", EdmPrimitiveTypeKind.Int16);
EdmComplexType derivedSubjectInfo = new EdmComplexType(MyNameSpace, "DerivedSubject", subjectInfo);
derivedSubjectInfo.AddStructuralProperty("Teacher", EdmPrimitiveTypeKind.String);
EdmComplexType derivedDerivedSubjectInfo = new EdmComplexType(MyNameSpace, "DerivedDerivedSubject", derivedSubjectInfo);
derivedDerivedSubjectInfo.AddStructuralProperty("Classroom", EdmPrimitiveTypeKind.String);
EdmCollectionTypeReference subjectsCollection = new EdmCollectionTypeReference(new EdmCollectionType(new EdmComplexTypeReference(subjectInfo, isNullable: true)));
studentInfo = new EdmEntityType(MyNameSpace, "Student");
studentInfo.AddStructuralProperty("Info", new EdmComplexTypeReference(personalInfo, isNullable: false));
studentInfo.AddProperty(new EdmStructuralProperty(studentInfo, "Subjects", subjectsCollection));
// enum with flags
var enumFlagsType = new EdmEnumType(MyNameSpace, "ColorFlags", isFlags: true);
enumFlagsType.AddMember("Red", new EdmIntegerConstant(1));
enumFlagsType.AddMember("Green", new EdmIntegerConstant(2));
enumFlagsType.AddMember("Blue", new EdmIntegerConstant(4));
studentInfo.AddStructuralProperty("ClothesColors", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEnumTypeReference(enumFlagsType, true))));
EdmCollectionTypeReference hobbiesCollection = new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(isNullable: false)));
studentInfo.AddProperty(new EdmStructuralProperty(studentInfo, "Hobbies", hobbiesCollection));
model.AddElement(enumFlagsType);
model.AddElement(studentInfo);
model.AddElement(personalInfo);
model.AddElement(derivedPersonalInfo);
model.AddElement(derivedDerivedPersonalInfo);
model.AddElement(subjectInfo);
model.AddElement(derivedSubjectInfo);
model.AddElement(derivedDerivedSubjectInfo);
IEdmEntityContainer defaultContainer = new EdmEntityContainer("NS", "DefaultContainer");
model.AddElement(defaultContainer);
this.studentSet = new EdmEntitySet(defaultContainer, "MySet", this.studentInfo);
}
示例4: CreateModel
public static IEdmModel CreateModel(string ns)
{
EdmModel model = new EdmModel();
var defaultContainer = new EdmEntityContainer(ns, "DefaultContainer");
model.AddElement(defaultContainer);
var addressType = new EdmComplexType(ns, "Address");
addressType.AddProperty(new EdmStructuralProperty(addressType, "Road", EdmCoreModel.Instance.GetString(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", EdmCoreModel.Instance.GetString(false)));
personType.AddProperty(new EdmStructuralProperty(personType, "LastName", EdmCoreModel.Instance.GetString(false)));
personType.AddProperty(new EdmStructuralProperty(personType, "Address", new EdmComplexTypeReference(addressType, true)));
personType.AddProperty(new EdmStructuralProperty(personType, "Descriptions", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(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", EdmCoreModel.Instance.GetInt32(false)));
numberComboType.AddProperty(new EdmStructuralProperty(numberComboType, "Middle", EdmCoreModel.Instance.GetInt64(false)));
numberComboType.AddProperty(new EdmStructuralProperty(numberComboType, "Large", EdmCoreModel.Instance.GetDecimal(false)));
model.AddElement(numberComboType);
var productType = new EdmEntityType(ns, "Product");
var productIdProperty = new EdmStructuralProperty(productType, "ProductId", EdmCoreModel.Instance.GetInt32(false));
productType.AddProperty(productIdProperty);
productType.AddKeys(new IEdmStructuralProperty[] { productIdProperty });
productType.AddProperty(new EdmStructuralProperty(productType, "Quantity", EdmCoreModel.Instance.GetInt64(false)));
productType.AddProperty(new EdmStructuralProperty(productType, "LifeTimeInSeconds", EdmCoreModel.Instance.GetDecimal(false)));
productType.AddProperty(new EdmStructuralProperty(productType, "TheCombo", new EdmComplexTypeReference(numberComboType, true)));
productType.AddProperty(new EdmStructuralProperty(productType, "LargeNumbers", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetDecimal(false)))));
model.AddElement(productType);
var productsSet = new EdmEntitySet(defaultContainer, "Products", productType);
defaultContainer.AddElement(productsSet);
var productsProperty = personType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
{
Name = "Products",
Target = productType,
TargetMultiplicity = EdmMultiplicity.Many
});
peopleSet.AddNavigationTarget(productsProperty, productsSet);
IEnumerable<EdmError> errors;
model.Validate(out errors);
return model;
}
示例5: InstanceAnnotationsReaderIntegrationTests
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);
}
示例6: WriterShouldNotIncludeTypeNameForCollectionOfDerivedType
public void WriterShouldNotIncludeTypeNameForCollectionOfDerivedType()
{
// JSON Light: writer doesn't include type name for collection of derived type
// If I have a collection property declared in metadata as Collection(Edm.Geography),
// and at serialization type, it's clearly a Collection(Edm.GeographyPoint),
// we won't write the type name for that property by default (i.e., minimal metadata mode).
var model = new EdmModel();
var entityType = new EdmEntityType("Var1", "Type");
entityType.AddKeys(entityType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
entityType.AddProperty(new EdmStructuralProperty(entityType, "Geographies", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetSpatial(EdmPrimitiveTypeKind.Geography, false)))));
model.AddElement(entityType);
var writerSettings = new ODataMessageWriterSettings();
writerSettings.SetContentType(ODataFormat.Json);
writerSettings.DisableMessageStreamDisposal = true;
var message = new InMemoryMessage { Stream = new MemoryStream() };
using (ODataMessageWriter odataMessageWriter = new ODataMessageWriter((IODataRequestMessage)message, writerSettings, model))
{
ODataWriter odataWriter = odataMessageWriter.CreateODataEntryWriter();
odataWriter.WriteStart(
new ODataEntry
{
TypeName = "Var1.Type",
Properties = new[]
{
new ODataProperty()
{
Name = "Id",
Value = 1
},
new ODataProperty()
{
Name = "Geographies",
Value = new ODataCollectionValue
{
Items = new[]
{
GeographyPoint.Create(0,0),
GeographyPoint.Create(1,1),
GeographyPoint.Create(2,2)
}
}
},
}
});
odataWriter.WriteEnd();
odataWriter.Flush();
}
message.Stream.Position = 0;
var output = new StreamReader(message.Stream).ReadToEnd();
Assert.IsFalse(output.Contains("Collection(Edm.GeographyPoint)"), @"output.Contains(""Collection(Edm.GeographyPoint)"" == false");
}
示例7: 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;
}
示例8: DeltaLinkWriterIntegrationTests
static DeltaLinkWriterIntegrationTests()
{
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);
}
示例9: ODataEntityReferenceLinksTests
static ODataEntityReferenceLinksTests()
{
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, "Customers", EntityType);
defaultContainer.AddElement(EntitySet);
EdmModel = TestUtils.WrapReferencedModelsToMainModel("TestNamespace", "DefaultContainer", tmpModel);
MessageReaderSettingsReadAndValidateCustomInstanceAnnotations = new ODataMessageReaderSettings { ShouldIncludeAnnotation = ODataUtils.CreateAnnotationFilter("*") };
}
示例10: 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();
}
示例11: TestElementInterfaceCriticalPropertyValueMustNotBeNull
public void TestElementInterfaceCriticalPropertyValueMustNotBeNull()
{
var expectedErrors = new EdmLibTestErrors()
{
{ null, null, EdmErrorCode.InterfaceCriticalPropertyValueMustNotBeNull }
};
var baseEntity = new EdmEntityType("DefaultNamespace", "BaseEntity");
var navProperty = new StubEdmNavigationProperty("Nav")
{
DeclaringType = baseEntity,
Partner = new StubEdmNavigationProperty("Partner") { DeclaringType = baseEntity, Type = new EdmEntityTypeReference(baseEntity, false) }
};
baseEntity.AddProperty(navProperty);
this.ValidateElement(navProperty, expectedErrors);
this.ValidateElement(baseEntity, expectedErrors);
expectedErrors = new EdmLibTestErrors();
var entity = new EdmEntityType("DefaultNamespace", "Entity", baseEntity);
this.ValidateElement(entity, expectedErrors);
}
示例12: 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;
}
示例13: CreateModel
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;
}
示例14: WriteContainedFeed
public void WriteContainedFeed()
{
EdmEntityType entityType = new EdmEntityType("NS", "Entity");
entityType.AddProperty(new EdmStructuralProperty(entityType, "Id", EdmCoreModel.Instance.GetInt32(false)));
EdmEntityType expandEntityType = new EdmEntityType("NS", "ExpandEntity");
expandEntityType.AddProperty(new EdmStructuralProperty(expandEntityType, "Id", EdmCoreModel.Instance.GetInt32(false)));
expandEntityType.AddProperty(new EdmStructuralProperty(expandEntityType, "Name", EdmCoreModel.Instance.GetString(false)));
entityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { ContainsTarget = true, Name = "Property1", Target = expandEntityType, TargetMultiplicity = EdmMultiplicity.Many });
EdmOperation operation = new EdmFunction("NS", "Foo", EdmCoreModel.Instance.GetInt16(true));
operation.AddParameter("entry", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(entityType, false))));
Action<ODataJsonLightOutputContext> test = outputContext =>
{
var entry1 = new ODataEntry();
entry1.Properties = new List<ODataProperty>()
{
new ODataProperty() { Name = "ID", Value = 1 },
};
var entry2 = new ODataEntry();
entry2.Properties = new List<ODataProperty>()
{
new ODataProperty() { Name = "ID", Value = 1 },
new ODataProperty() { Name = "Name", Value = "TestName"}
};
var parameterWriter = new ODataJsonLightParameterWriter(outputContext, operation: null);
parameterWriter.WriteStart();
var entryWriter = parameterWriter.CreateFeedWriter("feed");
entryWriter.WriteStart(new ODataFeed());
entryWriter.WriteStart(entry1);
entryWriter.WriteStart(new ODataNavigationLink()
{
Name = "Property1",
IsCollection = true
});
entryWriter.WriteStart(new ODataFeed());
entryWriter.WriteStart(entry2);
entryWriter.WriteEnd();
entryWriter.WriteEnd();
entryWriter.WriteEnd();
entryWriter.WriteEnd();
entryWriter.WriteEnd();
parameterWriter.WriteEnd();
parameterWriter.Flush();
};
WriteAndValidate(test, "{\"feed\":[{\"ID\":1,\"Property1\":[{\"ID\":1,\"Name\":\"TestName\"}]}]}", writingResponse: false);
}
示例15: WriteDerivedEntityInFeed
public void WriteDerivedEntityInFeed()
{
EdmEntityType entityType = new EdmEntityType("NS", "Entity");
IEdmStructuralProperty keyProp = new EdmStructuralProperty(entityType, "Id", EdmCoreModel.Instance.GetInt32(false));
entityType.AddProperty(keyProp);
entityType.AddKeys(keyProp);
EdmEntityType derivedType = new EdmEntityType("NS", "DerivedType", entityType);
derivedType.AddProperty(new EdmStructuralProperty(derivedType, "Name", EdmCoreModel.Instance.GetString(false)));
EdmOperation operation = new EdmFunction("NS", "Foo", EdmCoreModel.Instance.GetInt16(true));
operation.AddParameter("feed", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(entityType, false))));
Action<ODataJsonLightOutputContext> test = outputContext =>
{
var entry = new ODataEntry()
{
TypeName = "NS.DerivedType",
};
entry.Properties = new List<ODataProperty>()
{
new ODataProperty() { Name = "ID", Value = 1 },
new ODataProperty() { Name = "Name", Value = "TestName"}
};
var parameterWriter = new ODataJsonLightParameterWriter(outputContext, operation: null);
parameterWriter.WriteStart();
var entryWriter = parameterWriter.CreateFeedWriter("feed");
entryWriter.WriteStart(new ODataFeed());
entryWriter.WriteStart(entry);
entryWriter.WriteEnd();
entryWriter.WriteEnd();
parameterWriter.WriteEnd();
parameterWriter.Flush();
};
WriteAndValidate(test, "{\"feed\":[{\"@odata.type\":\"#NS.DerivedType\",\"ID\":1,\"Name\":\"TestName\"}]}", writingResponse: false);
}