C# Microsoft.AspNetCore.OData-自定义批注$metadata
在Edm模型生成过程中,是否有方法向$metadata添加复杂的自定义注释 示例(下面的XML由.NET自动生成):C# Microsoft.AspNetCore.OData-自定义批注$metadata,c#,.net-core,annotations,odata,asp.net-core-webapi,C#,.net Core,Annotations,Odata,Asp.net Core Webapi,在Edm模型生成过程中,是否有方法向$metadata添加复杂的自定义注释 示例(下面的XML由.NET自动生成): ) 。。。但找不到添加“复杂”注释类型的方法 谢谢你的帮助 EdmModel model = new EdmModel(); // Entity Type EdmEntityType person = new EdmEntityType("NS", "Person"); model.AddElement(person); // En
)
。。。但找不到添加“复杂”注释类型的方法
谢谢你的帮助
EdmModel model = new EdmModel();
// Entity Type
EdmEntityType person = new EdmEntityType("NS", "Person");
model.AddElement(person);
// EntityContainer
EdmEntityContainer container = new EdmEntityContainer("NS", "Default");
EdmEntitySet persons = container.AddEntitySet("Persons", person);
model.AddElement(container);
// Complex Type
EdmComplexType dataField = new EdmComplexType("UI", "DataField");
dataField.AddStructuralProperty("Value", EdmCoreModel.Instance.GetAnnotationPath(true));
model.AddElement(dataField);
// Term Type
EdmTerm term = new EdmTerm("UI", "LineItem", new EdmComplexTypeReference(dataField, true));
model.AddElement(term);
EdmRecordExpression record = new EdmRecordExpression(new EdmPropertyConstructor("Value", new EdmPathExpression("Name")));
EdmVocabularyAnnotation annotation = new EdmVocabularyAnnotation(persons, term, record);
annotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline); // no necessary
model.SetVocabularyAnnotation(annotation);
然后,您可以调用“CsdlWriter.TryWriteCsdl”来编写CSDL并验证为:
EdmModel model = new EdmModel();
// Entity Type
EdmEntityType person = new EdmEntityType("NS", "Person");
model.AddElement(person);
// EntityContainer
EdmEntityContainer container = new EdmEntityContainer("NS", "Default");
EdmEntitySet persons = container.AddEntitySet("Persons", person);
model.AddElement(container);
// Complex Type
EdmComplexType dataField = new EdmComplexType("UI", "DataField");
dataField.AddStructuralProperty("Value", EdmCoreModel.Instance.GetAnnotationPath(true));
model.AddElement(dataField);
// Term Type
EdmTerm term = new EdmTerm("UI", "LineItem", new EdmComplexTypeReference(dataField, true));
model.AddElement(term);
EdmRecordExpression record = new EdmRecordExpression(new EdmPropertyConstructor("Value", new EdmPathExpression("Name")));
EdmVocabularyAnnotation annotation = new EdmVocabularyAnnotation(persons, term, record);
annotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline); // no necessary
model.SetVocabularyAnnotation(annotation);