本文整理汇总了C#中Microsoft.OData.Edm.Library.EdmModel.SetOptimisticConcurrencyControlAnnotation方法的典型用法代码示例。如果您正苦于以下问题:C# EdmModel.SetOptimisticConcurrencyControlAnnotation方法的具体用法?C# EdmModel.SetOptimisticConcurrencyControlAnnotation怎么用?C# EdmModel.SetOptimisticConcurrencyControlAnnotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.OData.Edm.Library.EdmModel
的用法示例。
在下文中一共展示了EdmModel.SetOptimisticConcurrencyControlAnnotation方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AutoComputeETagWithOptimisticConcurrencyControlAnnotation
public void AutoComputeETagWithOptimisticConcurrencyControlAnnotation()
{
const string expected = "{" +
"\"@odata.context\":\"http://example.com/$metadata#People/$entity\"," +
"\"@odata.id\":\"People(123)\"," +
"\"@odata.etag\":\"W/\\\"'lucy',12306\\\"\"," +
"\"@odata.editLink\":\"People(123)\"," +
"\"@odata.mediaEditLink\":\"People(123)/$value\"," +
"\"ID\":123," +
"\"Name\":\"lucy\"," +
"\"Class\":12306," +
"\"Alias\":\"lily\"}";
EdmModel model = new EdmModel();
EdmEntityType personType = new EdmEntityType("MyNs", "Person", null, false, false, true);
personType.AddKeys(personType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32));
var nameProperty = personType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(isNullable: true));
var classProperty = personType.AddStructuralProperty("Class", EdmPrimitiveTypeKind.Int32);
personType.AddStructuralProperty("Alias", EdmCoreModel.Instance.GetString(isNullable: true), null, EdmConcurrencyMode.Fixed);
var container = new EdmEntityContainer("MyNs", "Container");
model.AddElement(personType);
container.AddEntitySet("People", personType);
model.AddElement(container);
IEdmEntitySet peopleSet = model.FindDeclaredEntitySet("People");
model.SetOptimisticConcurrencyControlAnnotation(peopleSet, new[] {nameProperty, classProperty});
ODataEntry entry = new ODataEntry
{
Properties = new[]
{
new ODataProperty {Name = "ID", Value = 123},
new ODataProperty {Name = "Name", Value = "lucy"},
new ODataProperty {Name = "Class", Value = 12306},
new ODataProperty {Name = "Alias", Value = "lily"},
}
};
string actual = GetWriterOutputForContentTypeAndKnobValue(entry, model, peopleSet, personType);
Assert.Equal(expected, actual);
}
示例2: TestCoreOptimisticConcurrencyControlInlineAnnotation
public void TestCoreOptimisticConcurrencyControlInlineAnnotation()
{
EdmModel model = new EdmModel();
EdmEntityContainer container = new EdmEntityContainer("DefaultNamespace", "Container");
EdmEntityType personType = new EdmEntityType("DefaultNamespace", "Person");
EdmStructuralProperty propertyId = personType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(false));
personType.AddKeys(propertyId);
IEdmStructuralProperty concurrencyProperty = personType.AddStructuralProperty("Concurrency", EdmCoreModel.Instance.GetInt32(true));
model.AddElement(personType);
container.AddEntitySet("People", personType);
model.AddElement(container);
container.AddEntitySet("Students", personType);
IEdmEntitySet peopleSet = model.FindDeclaredEntitySet("People");
model.SetOptimisticConcurrencyControlAnnotation(peopleSet, new[] { concurrencyProperty });
model.SetOptimisticConcurrencyControlAnnotation(peopleSet, new[] { concurrencyProperty });
IEdmEntitySet studentSet = model.FindDeclaredEntitySet("Students");
model.SetOptimisticConcurrencyControlAnnotation(studentSet, new[] { concurrencyProperty });
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();
const string expected = @"<?xml version=""1.0"" encoding=""utf-16""?>
<Schema Namespace=""DefaultNamespace"" 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"" />
<Property Name=""Concurrency"" Type=""Edm.Int32"" />
</EntityType>
<EntityContainer Name=""Container"">
<EntitySet Name=""People"" EntityType=""DefaultNamespace.Person"">
<Annotation Term=""Org.OData.Core.V1.OptimisticConcurrencyControl"">
<Collection>
<PropertyPath>Concurrency</PropertyPath>
</Collection>
</Annotation>
</EntitySet>
<EntitySet Name=""Students"" EntityType=""DefaultNamespace.Person"">
<Annotation Term=""Org.OData.Core.V1.OptimisticConcurrencyControl"">
<Collection>
<PropertyPath>Concurrency</PropertyPath>
</Collection>
</Annotation>
</EntitySet>
</EntityContainer>
</Schema>";
Assert.AreEqual(expected, actual);
}