本文整理汇总了C#中Microsoft.OData.Edm.Library.EdmEntityType.AsReference方法的典型用法代码示例。如果您正苦于以下问题:C# EdmEntityType.AsReference方法的具体用法?C# EdmEntityType.AsReference怎么用?C# EdmEntityType.AsReference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.OData.Edm.Library.EdmEntityType
的用法示例。
在下文中一共展示了EdmEntityType.AsReference方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetEntityKeyValue_MultipleKeys_DerivedType_ForDateAndTimeOfDay
public void GetEntityKeyValue_MultipleKeys_DerivedType_ForDateAndTimeOfDay()
{
// Arrange
var entityInstance = new { Key1 = new Date(2015, 2, 26), Key2 = new TimeOfDay(1, 2, 3, 4) };
EdmEntityType baseEntityType = new EdmEntityType("NS", "Name");
baseEntityType.AddKeys(baseEntityType.AddStructuralProperty("Key1", EdmPrimitiveTypeKind.Date));
baseEntityType.AddKeys(baseEntityType.AddStructuralProperty("Key2", EdmPrimitiveTypeKind.TimeOfDay));
EdmEntityType derivedEntityType = new EdmEntityType("NS", "Derived", baseEntityType);
EntityInstanceContext entityInstanceContext = new EntityInstanceContext(_writeContext,
derivedEntityType.AsReference(), entityInstance);
// Act
var keyValue = ConventionsHelpers.GetEntityKeyValue(entityInstanceContext);
// Assert
Assert.Equal("Key1=2015-02-26,Key2=01:02:03.0040000", keyValue);
}
示例2: CreateSelectExpandNode_ReturnsDifferentSelectExpandNode_IfEntityTypeIsDifferent
public void CreateSelectExpandNode_ReturnsDifferentSelectExpandNode_IfEntityTypeIsDifferent()
{
// Arrange
IEdmEntityType customerType = _customerSet.EntityType();
IEdmEntityType derivedCustomerType = new EdmEntityType("NS", "DerivedCustomer", customerType);
EntityInstanceContext entity1 = new EntityInstanceContext(_writeContext, customerType.AsReference(), new Customer());
EntityInstanceContext entity2 = new EntityInstanceContext(_writeContext, derivedCustomerType.AsReference(), new Customer());
// Act
var selectExpandNode1 = _serializer.CreateSelectExpandNode(entity1);
var selectExpandNode2 = _serializer.CreateSelectExpandNode(entity2);
// Assert
Assert.NotSame(selectExpandNode1, selectExpandNode2);
}
示例3: GetEntityKeyValue_MultipleKeys_DerivedType
public void GetEntityKeyValue_MultipleKeys_DerivedType()
{
// Arrange
var entityInstance = new { Key1 = "key1", Key2 = 2, Key3 = true };
EdmEntityType baseEntityType = new EdmEntityType("NS", "Name");
baseEntityType.AddKeys(baseEntityType.AddStructuralProperty("Key1", EdmPrimitiveTypeKind.String));
baseEntityType.AddKeys(baseEntityType.AddStructuralProperty("Key2", EdmPrimitiveTypeKind.Int32));
baseEntityType.AddKeys(baseEntityType.AddStructuralProperty("Key3", EdmPrimitiveTypeKind.Boolean));
EdmEntityType derivedEntityType = new EdmEntityType("NS", "Derived", baseEntityType);
EntityInstanceContext entityInstanceContext = new EntityInstanceContext(_writeContext, derivedEntityType.AsReference(), entityInstance);
// Act
var keyValue = ConventionsHelpers.GetEntityKeyValue(entityInstanceContext);
// Assert
Assert.Equal("Key1='key1',Key2=2,Key3=true", keyValue);
}
示例4: GetEntityKeyValue_DerivedType
public void GetEntityKeyValue_DerivedType()
{
// Arrange
var entityInstance = new { Key = "key" };
EdmEntityType baseEntityType = new EdmEntityType("NS", "Name");
baseEntityType.AddKeys(baseEntityType.AddStructuralProperty("Key", EdmPrimitiveTypeKind.String));
EdmEntityType derivedEntityType = new EdmEntityType("NS", "Derived", baseEntityType);
EntityInstanceContext entityInstanceContext = new EntityInstanceContext(_writeContext, derivedEntityType.AsReference(), entityInstance);
// Act
var keyValue = ConventionsHelpers.GetEntityKeyValue(entityInstanceContext);
// Assert
Assert.Equal("'key'", keyValue);
}
示例5: GetEntityKeyValue_ThrowsForNullKeys_WithMultipleKeys
public void GetEntityKeyValue_ThrowsForNullKeys_WithMultipleKeys()
{
// Arrange
var entityInstance = new { Key1 = "abc", Key2 = "def", Key3 = (string)null };
EdmEntityType entityType = new EdmEntityType("NS", "Name");
entityType.AddKeys(entityType.AddStructuralProperty("Key1", EdmPrimitiveTypeKind.String));
entityType.AddKeys(entityType.AddStructuralProperty("Key2", EdmPrimitiveTypeKind.Int32));
entityType.AddKeys(entityType.AddStructuralProperty("Key3", EdmPrimitiveTypeKind.Boolean));
EntityInstanceContext entityInstanceContext = new EntityInstanceContext(_writeContext, entityType.AsReference(), entityInstance);
// Act & Assert
Assert.Throws<InvalidOperationException>(
() => ConventionsHelpers.GetEntityKeyValue(entityInstanceContext),
"Key property 'Key3' of type 'NS.Name' is null. Key properties cannot have null values.");
}
示例6: GetEntityKeyValue_MultipleKeys_ForDateAndTimeOfDay
public void GetEntityKeyValue_MultipleKeys_ForDateAndTimeOfDay()
{
// Arrange
var entityInstance = new { Key1 = new Date(2015, 12, 2), Key2 = new TimeOfDay(4, 3, 2, 1) };
EdmEntityType entityType = new EdmEntityType("NS", "Name");
entityType.AddKeys(entityType.AddStructuralProperty("Key1", EdmPrimitiveTypeKind.Date));
entityType.AddKeys(entityType.AddStructuralProperty("Key2", EdmPrimitiveTypeKind.TimeOfDay));
EntityInstanceContext entityInstanceContext = new EntityInstanceContext(_writeContext,
entityType.AsReference(), entityInstance);
// Act
var keyValue = ConventionsHelpers.GetEntityKeyValue(entityInstanceContext);
// Assert
Assert.Equal("Key1=2015-12-02,Key2=04:03:02.0010000", keyValue);
}
示例7: GetEntityKeyValue_SingleKey_DifferentDataTypes
public void GetEntityKeyValue_SingleKey_DifferentDataTypes(object value, object expectedValue)
{
// Arrange
EdmEntityType entityType = new EdmEntityType("NS", "Name");
entityType.AddKeys(entityType.AddStructuralProperty("Property", EdmPrimitiveTypeKind.String));
var entityInstance = new { Property = value };
EntityInstanceContext entityInstanceContext = new EntityInstanceContext(_writeContext, entityType.AsReference(), entityInstance);
// Act
var keyValue = ConventionsHelpers.GetEntityKeyValue(entityInstanceContext);
// Assert
Assert.Equal(expectedValue, keyValue);
}