本文整理汇总了C#中Microsoft.OData.Edm.Library.EdmModel.AddVocabularyAnnotation方法的典型用法代码示例。如果您正苦于以下问题:C# EdmModel.AddVocabularyAnnotation方法的具体用法?C# EdmModel.AddVocabularyAnnotation怎么用?C# EdmModel.AddVocabularyAnnotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.OData.Edm.Library.EdmModel
的用法示例。
在下文中一共展示了EdmModel.AddVocabularyAnnotation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ODataFeedAndEntryTypeContextTests
static ODataFeedAndEntryTypeContextTests()
{
Model = new EdmModel();
EntitySetElementType = new EdmEntityType("ns", "Customer");
ExpectedEntityType = new EdmEntityType("ns", "VipCustomer", EntitySetElementType);
ActualEntityType = new EdmEntityType("ns", "DerivedVipCustomer", ExpectedEntityType);
EdmEntityContainer defaultContainer = new EdmEntityContainer("ns", "DefaultContainer");
Model.AddElement(defaultContainer);
Model.AddVocabularyAnnotation(new EdmAnnotation(defaultContainer, UrlConventionsConstants.ConventionTerm, UrlConventionsConstants.KeyAsSegmentAnnotationValue));
EntitySet = new EdmEntitySet(defaultContainer, "Customers", EntitySetElementType);
Model.AddElement(EntitySetElementType);
Model.AddElement(ExpectedEntityType);
Model.AddElement(ActualEntityType);
defaultContainer.AddElement(EntitySet);
SerializationInfo = new ODataFeedAndEntrySerializationInfo { NavigationSourceName = "MyCustomers", NavigationSourceEntityTypeName = "ns.MyCustomer", ExpectedTypeName = "ns.MyVipCustomer" };
SerializationInfoWithEdmUnknowEntitySet = new ODataFeedAndEntrySerializationInfo() { NavigationSourceName = null, NavigationSourceEntityTypeName = "ns.MyCustomer", ExpectedTypeName = "ns.MyVipCustomer", NavigationSourceKind = EdmNavigationSourceKind.UnknownEntitySet };
TypeContextWithoutModel = ODataFeedAndEntryTypeContext.Create(SerializationInfo, navigationSource: null, navigationSourceEntityType: null, expectedEntityType: null, model: Model, throwIfMissingTypeInfo: true);
TypeContextWithModel = ODataFeedAndEntryTypeContext.Create(/*serializationInfo*/null, EntitySet, EntitySetElementType, ExpectedEntityType, Model, throwIfMissingTypeInfo: true);
TypeContextWithEdmUnknowEntitySet = ODataFeedAndEntryTypeContext.Create(SerializationInfoWithEdmUnknowEntitySet, navigationSource: null, navigationSourceEntityType: null, expectedEntityType: null, model: Model, throwIfMissingTypeInfo: true);
BaseTypeContextThatThrows = ODataFeedAndEntryTypeContext.Create(serializationInfo: null, navigationSource: null, navigationSourceEntityType: null, expectedEntityType: null, model: Model, throwIfMissingTypeInfo: true);
BaseTypeContextThatWillNotThrow = ODataFeedAndEntryTypeContext.Create(serializationInfo: null, navigationSource: null, navigationSourceEntityType: null, expectedEntityType: null, model: Model, throwIfMissingTypeInfo: false);
}
示例2: CreateEntryWithKeyAsSegmentConvention
private static ODataEntry CreateEntryWithKeyAsSegmentConvention(bool addAnnotation, bool? useKeyAsSegment)
{
var model = new EdmModel();
var container = new EdmEntityContainer("Fake", "Container");
model.AddElement(container);
if (addAnnotation)
{
model.AddVocabularyAnnotation(new EdmAnnotation(container, UrlConventionsConstants.ConventionTerm, UrlConventionsConstants.KeyAsSegmentAnnotationValue));
}
EdmEntityType entityType = new EdmEntityType("Fake", "FakeType");
entityType.AddKeys(entityType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
model.AddElement(entityType);
var entitySet = new EdmEntitySet(container, "FakeSet", entityType);
container.AddElement(entitySet);
var metadataContext = new ODataMetadataContext(
true,
ODataReaderBehavior.DefaultBehavior.OperationsBoundToEntityTypeMustBeContainerQualified,
new EdmTypeReaderResolver(model, ODataReaderBehavior.DefaultBehavior),
model,
new Uri("http://temp.org/$metadata"),
null /*requestUri*/);
var thing = new ODataEntry {Properties = new[] {new ODataProperty {Name = "Id", Value = 1}}};
thing.SetAnnotation(new ODataTypeAnnotation(entitySet, entityType));
thing.MetadataBuilder = metadataContext.GetEntityMetadataBuilderForReader(new TestJsonLightReaderEntryState { Entry = thing, SelectedProperties = new SelectedPropertiesNode("*")}, useKeyAsSegment);
return thing;
}
示例3: UrlConventionFromAnnotationShouldReturnDefaultIfAnnotationMissing
public void UrlConventionFromAnnotationShouldReturnDefaultIfAnnotationMissing()
{
var container = new EdmEntityContainer("Fake", "Container");
var model = new EdmModel();
model.AddElement(container);
model.AddVocabularyAnnotation(new EdmAnnotation(container, new EdmTerm("Fake", "Fake", EdmPrimitiveTypeKind.Stream), EdmNullExpression.Instance));
UrlConvention.ForModel(model).GenerateKeyAsSegment.Should().BeFalse();
}
示例4: UrlConventionFromAnnotationShouldReturnKeyAsSegmentIfAnnotationFound
public void UrlConventionFromAnnotationShouldReturnKeyAsSegmentIfAnnotationFound()
{
var container = new EdmEntityContainer("Fake", "Container");
var model = new EdmModel();
model.AddElement(container);
model.AddVocabularyAnnotation(new EdmAnnotation(container, UrlConventionsConstants.ConventionTerm, UrlConventionsConstants.KeyAsSegmentAnnotationValue));
UrlConvention.ForModel(model).GenerateKeyAsSegment.Should().BeTrue();
}
示例5: UrlConventionFromAnnotationShouldReturnDefaultIfAnnotationHasWrongValue
public void UrlConventionFromAnnotationShouldReturnDefaultIfAnnotationHasWrongValue()
{
var container = new EdmEntityContainer("Fake", "Container");
var model = new EdmModel();
model.AddElement(container);
model.AddVocabularyAnnotation(new EdmAnnotation(container, UrlConventionsConstants.ConventionTerm, new EdmStringConstant("fake")));
UrlConvention.ForModel(model).GenerateKeyAsSegment.Should().BeFalse();
}
示例6: InterfaceCriticalPropertyValueMustNotBeNullOnlyModel
public static IEdmModel InterfaceCriticalPropertyValueMustNotBeNullOnlyModel()
{
var model = new EdmModel();
var valueTerm = new EdmTerm("DefaultNamespace", "Note", EdmCoreModel.Instance.GetString(true));
model.AddElement(valueTerm);
var valueAnnotation = new MutableValueAnnotation()
{
Target = valueTerm
};
model.AddVocabularyAnnotation(valueAnnotation);
return model;
}
示例7: EdmExpressionKindInterfaceCriticalKindValueUnexpectedOnlyModel
public static IEdmModel EdmExpressionKindInterfaceCriticalKindValueUnexpectedOnlyModel()
{
var model = new EdmModel();
var valueTerm = new EdmTerm("DefaultNamespace", "Note", EdmCoreModel.Instance.GetString(true));
model.AddElement(valueTerm);
var badString = new CustomStringConstant("foo", EdmExpressionKind.None, EdmValueKind.String);
var valueAnnotation = new EdmAnnotation(
valueTerm,
valueTerm,
badString);
model.AddVocabularyAnnotation(valueAnnotation);
return model;
}
示例8: ConstructibleVocabularySerializingAnnotationsWithNoTerm
public void ConstructibleVocabularySerializingAnnotationsWithNoTerm()
{
var stockModel = new EdmModel();
var customer = new EdmEntityType("NS1", "Customer");
var customerId = customer.AddStructuralProperty("CustomerID", EdmCoreModel.Instance.GetString(false));
customer.AddKeys(customerId);
stockModel.AddElement(customer);
var annotation = new MutableValueAnnotation()
{
Target = customer,
Value = new EdmStringConstant("Hello world2!"),
};
stockModel.AddVocabularyAnnotation(annotation);
var stringWriter = new StringWriter();
var xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings() { Indent = true });
IEnumerable<EdmError> serializationErrors;
stockModel.TryWriteCsdl(xmlWriter, out serializationErrors);
xmlWriter.Close();
Assert.AreEqual(1, serializationErrors.Count(), "Error on serialization");
}
示例9: InterfaceCriticalPropertyValueMustNotBeNullUsingBinaryValueModel
public static IEdmModel InterfaceCriticalPropertyValueMustNotBeNullUsingBinaryValueModel()
{
var model = new EdmModel();
var valueTerm = new EdmTerm("NS", "Note", EdmCoreModel.Instance.GetBinary(true));
model.AddElement(valueTerm);
var badValue = new CustomBinaryConstant(null);
var valueAnnotation = new EdmAnnotation(
valueTerm,
valueTerm,
badValue);
model.AddVocabularyAnnotation(valueAnnotation);
return model;
}
示例10: IsTypeResultFalseEvaluationModel
public static IEdmModel IsTypeResultFalseEvaluationModel()
{
var model = new EdmModel();
var booleanFlag = new EdmTerm("NS", "BooleanFlag", EdmCoreModel.Instance.GetBoolean(true));
model.AddElement(booleanFlag);
var valueAnnotation = new EdmAnnotation(
booleanFlag,
booleanFlag,
new EdmIsTypeExpression(new EdmIntegerConstant(32), EdmCoreModel.Instance.GetString(true)));
valueAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.OutOfLine);
model.AddVocabularyAnnotation(valueAnnotation);
return model;
}
示例11: OutOfLineValueAnnotationWithAnnotationModel
public static EdmModel OutOfLineValueAnnotationWithAnnotationModel()
{
EdmModel model = new EdmModel();
EdmComplexType simpleType = new EdmComplexType("DefaultNamespace", "SimpleType");
simpleType.AddStructuralProperty("Data", EdmCoreModel.Instance.GetString(true));
model.AddElement(simpleType);
EdmTerm note = new EdmTerm("DefaultNamespace", "Note", EdmCoreModel.Instance.GetString(true));
model.AddElement(note);
EdmAnnotation valueAnnotation = new EdmAnnotation(
simpleType,
note,
new EdmStringConstant("ComplexTypeNote"));
valueAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.OutOfLine);
model.AddVocabularyAnnotation(valueAnnotation);
XElement annotationElement =
new XElement("{http://foo}Annotation", "1");
var annotation = new EdmStringConstant(EdmCoreModel.Instance.GetString(false), annotationElement.ToString());
annotation.SetIsSerializedAsElement(model, true);
model.SetAnnotationValue(valueAnnotation, "http://foo", "Annotation", annotation);
return model;
}
示例12: ValueAnnotationInvalidTypeReferenceDurationConstantModel
public static IEdmModel ValueAnnotationInvalidTypeReferenceDurationConstantModel()
{
var model = new EdmModel();
var valueTerm = new EdmTerm("DefaultNamespace", "Note", EdmCoreModel.Instance.GetDuration(true));
model.AddElement(valueTerm);
var valueAnnotation = new EdmAnnotation(
valueTerm,
valueTerm,
new EdmDurationConstant(EdmCoreModel.Instance.GetDateTimeOffset(false), new TimeSpan(1, 99, 99, 99, 999)));
valueAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.OutOfLine);
model.AddVocabularyAnnotation(valueAnnotation);
return model;
}
示例13: IsTypeResultTrueEvaluationModel
public static IEdmModel IsTypeResultTrueEvaluationModel()
{
var model = new EdmModel();
var booleanFlag = new EdmComplexType("NS", "BooleanFlag");
var flag = booleanFlag.AddStructuralProperty("Flag", EdmCoreModel.Instance.GetBoolean(true));
model.AddElement(booleanFlag);
var booleanFlagTerm = new EdmTerm("NS", "BooleanFlagTerm", new EdmComplexTypeReference(booleanFlag, true));
model.AddElement(booleanFlagTerm);
var valueAnnotation = new EdmAnnotation(
booleanFlag,
booleanFlagTerm,
new EdmRecordExpression(
new EdmPropertyConstructor(flag.Name, new EdmIsTypeExpression(new EdmStringConstant("foo"), EdmCoreModel.Instance.GetString(true)))));
valueAnnotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.OutOfLine);
model.AddVocabularyAnnotation(valueAnnotation);
return model;
}
示例14: AddAnnotationWithNoTarget
public void AddAnnotationWithNoTarget()
{
var edmModel = new EdmModel();
var annotation = new MutableValueAnnotation();
this.VerifyThrowsException(typeof(InvalidOperationException), () => edmModel.AddVocabularyAnnotation(annotation));
}
示例15: EdmWriteAnnotationDemo
private static void EdmWriteAnnotationDemo()
{
Console.WriteLine("EdmWriteAnnotationDemo");
var model = new EdmModel();
var mail = new EdmEntityType("ns", "Mail");
model.AddElement(mail);
mail.AddKeys(mail.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
var person = new EdmEntityType("ns", "Person");
model.AddElement(person);
person.AddKeys(person.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
var mails = person.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
{
ContainsTarget = true,
Name = "Mails",
TargetMultiplicity = EdmMultiplicity.Many,
Target = mail,
});
var ann1 = new EdmAnnotation(mails, CoreVocabularyModel.DescriptionTerm, new EdmStringConstant("test1"));
ann1.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
model.AddVocabularyAnnotation(ann1);
var container = new EdmEntityContainer("ns", "container");
model.AddElement(container);
var people = container.AddEntitySet("People", person);
var ann2 = new EdmAnnotation(people, CoreVocabularyModel.DescriptionTerm, new EdmStringConstant("test2"));
model.AddVocabularyAnnotation(ann2);
ShowModel(model);
}