本文整理汇总了C#中Microsoft.OData.Edm.Library.EdmModel.SetLongDescriptionAnnotation方法的典型用法代码示例。如果您正苦于以下问题:C# EdmModel.SetLongDescriptionAnnotation方法的具体用法?C# EdmModel.SetLongDescriptionAnnotation怎么用?C# EdmModel.SetLongDescriptionAnnotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.OData.Edm.Library.EdmModel
的用法示例。
在下文中一共展示了EdmModel.SetLongDescriptionAnnotation方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestCoreDescriptionAnnotation
public void TestCoreDescriptionAnnotation()
{
EdmModel model = new EdmModel();
const string personTypeDescription = "this is person type.";
const string personTypeLongDescription = "this is person type, but with a longer description.";
const string overwritePersonDescription = "this is overwritten person type.";
const string propertyIdDescription = "this is property Id.";
const string structuralPropertyDescription = "this is structural property.";
const string stringTermDescription = "this is string term.";
const string entitySetDescription = "this is entitySet.";
const string singletonDescription = "this is singleton.";
EdmEntityContainer container = new EdmEntityContainer("Ns", "Container");
var personType = new EdmEntityType("Ns", "Person");
var propertyId = personType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(false));
personType.AddKeys(propertyId);
var structuralProperty = personType.AddStructuralProperty("Concurrency", EdmCoreModel.Instance.GetInt32(true));
model.AddElement(personType);
var entitySet = container.AddEntitySet("People", personType);
var driverSet = container.AddEntitySet("Drivers", personType);
var stringTerm = new EdmTerm("Ns", "HomeAddress", EdmCoreModel.Instance.GetString(true));
model.AddElement(stringTerm);
var singleton = container.AddSingleton("Boss", personType);
model.AddElement(container);
model.SetDescriptionAnnotation(personType, personTypeDescription);
model.SetDescriptionAnnotation(personType, overwritePersonDescription);
model.SetLongDescriptionAnnotation(personType, personTypeLongDescription);
model.SetDescriptionAnnotation(structuralProperty, structuralPropertyDescription);
model.SetDescriptionAnnotation(propertyId, propertyIdDescription);
model.SetDescriptionAnnotation(stringTerm, stringTermDescription);
model.SetDescriptionAnnotation(entitySet, entitySetDescription);
model.SetDescriptionAnnotation(singleton, singletonDescription);
Assert.AreEqual(overwritePersonDescription, model.GetDescriptionAnnotation(personType));
Assert.AreEqual(personTypeLongDescription, model.GetLongDescriptionAnnotation(personType));
Assert.AreEqual(structuralPropertyDescription, model.GetDescriptionAnnotation(structuralProperty));
Assert.AreEqual(propertyIdDescription, model.GetDescriptionAnnotation(propertyId));
Assert.AreEqual(stringTermDescription, model.GetDescriptionAnnotation(stringTerm));
Assert.AreEqual(entitySetDescription, model.GetDescriptionAnnotation(entitySet));
Assert.AreEqual(singletonDescription, model.GetDescriptionAnnotation(singleton));
Assert.IsNull(model.GetDescriptionAnnotation(driverSet));
const string expected = @"<?xml version=""1.0"" encoding=""utf-16""?>
<Schema Namespace=""Ns"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
<EntityType Name=""Person"">
<Key>
<PropertyRef Name=""Id"" />
</Key>
<Property Name=""Id"" Type=""Edm.Int32"" Nullable=""false"">
<Annotation Term=""Org.OData.Core.V1.Description"" String=""this is property Id."" />
</Property>
<Property Name=""Concurrency"" Type=""Edm.Int32"">
<Annotation Term=""Org.OData.Core.V1.Description"" String=""this is structural property."" />
</Property>
<Annotation Term=""Org.OData.Core.V1.Description"" String=""this is overwritten person type."" />
<Annotation Term=""Org.OData.Core.V1.LongDescription"" String=""this is person type, but with a longer description."" />
</EntityType>
<Term Name=""HomeAddress"" Type=""Edm.String"">
<Annotation Term=""Org.OData.Core.V1.Description"" String=""this is string term."" />
</Term>
<EntityContainer Name=""Container"">
<EntitySet Name=""People"" EntityType=""Ns.Person"">
<Annotation Term=""Org.OData.Core.V1.Description"" String=""this is entitySet."" />
</EntitySet>
<EntitySet Name=""Drivers"" EntityType=""Ns.Person"" />
<Singleton Name=""Boss"" Type=""Ns.Person"">
<Annotation Term=""Org.OData.Core.V1.Description"" String=""this is singleton."" />
</Singleton>
</EntityContainer>
</Schema>";
IEnumerable<EdmError> errors;
StringWriter sw = new StringWriter();
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.Encoding = System.Text.Encoding.UTF8;
XmlWriter xw = XmlWriter.Create(sw, settings);
model.TryWriteCsdl(xw, out errors);
xw.Flush();
xw.Close();
var actual = sw.ToString();
Assert.AreEqual(expected, actual);
IEdmModel parsedModel;
IEnumerable<EdmError> errs;
bool parsed = CsdlReader.TryParse(new XmlReader[] { XmlReader.Create(new StringReader(expected)) }, out parsedModel, out errs);
Assert.IsTrue(parsed, "parsed");
Assert.IsTrue(!errors.Any(), "No errors");
Assert.AreEqual(null, parsedModel.GetDescriptionAnnotation(personType));
Assert.AreEqual(null, parsedModel.GetDescriptionAnnotation(structuralProperty));
Assert.AreEqual(null, parsedModel.GetDescriptionAnnotation(propertyId));
Assert.AreEqual(null, parsedModel.GetDescriptionAnnotation(stringTerm));
Assert.AreEqual(null, parsedModel.GetDescriptionAnnotation(entitySet));
Assert.AreEqual(null, parsedModel.GetDescriptionAnnotation(singleton));
//.........这里部分代码省略.........