本文整理汇总了C#中Microsoft.OData.Edm.Library.EdmCollectionTypeReference类的典型用法代码示例。如果您正苦于以下问题:C# EdmCollectionTypeReference类的具体用法?C# EdmCollectionTypeReference怎么用?C# EdmCollectionTypeReference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EdmCollectionTypeReference类属于Microsoft.OData.Edm.Library命名空间,在下文中一共展示了EdmCollectionTypeReference类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: NonPrimitiveTypeRoundtripAtomTests
public NonPrimitiveTypeRoundtripAtomTests()
{
this.model = new EdmModel();
EdmComplexType personalInfo = new EdmComplexType(MyNameSpace, "PersonalInfo");
personalInfo.AddStructuralProperty("Age", EdmPrimitiveTypeKind.Int16);
personalInfo.AddStructuralProperty("Email", EdmPrimitiveTypeKind.String);
personalInfo.AddStructuralProperty("Tel", EdmPrimitiveTypeKind.String);
personalInfo.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Guid);
EdmComplexType subjectInfo = new EdmComplexType(MyNameSpace, "Subject");
subjectInfo.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
subjectInfo.AddStructuralProperty("Score", EdmPrimitiveTypeKind.Int16);
EdmCollectionTypeReference subjectsCollection = new EdmCollectionTypeReference(new EdmCollectionType(new EdmComplexTypeReference(subjectInfo, isNullable:true)));
EdmEntityType studentInfo = new EdmEntityType(MyNameSpace, "Student");
studentInfo.AddStructuralProperty("Info", new EdmComplexTypeReference(personalInfo, isNullable: false));
studentInfo.AddProperty(new EdmStructuralProperty(studentInfo, "Subjects", subjectsCollection));
EdmCollectionTypeReference hobbiesCollection = new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(isNullable: false)));
studentInfo.AddProperty(new EdmStructuralProperty(studentInfo, "Hobbies", hobbiesCollection));
model.AddElement(studentInfo);
model.AddElement(personalInfo);
model.AddElement(subjectInfo);
}
开发者ID:larsenjo,项目名称:odata.net,代码行数:27,代码来源:NonPrimitiveTypeRoundtripAtomTests.cs
示例2: BuildCustomers
private static void BuildCustomers(IEdmModel model)
{
IEdmEntityType customerType = model.SchemaElements.OfType<IEdmEntityType>().First(e => e.Name == "Customer");
IEdmEntityObject[] untypedCustomers = new IEdmEntityObject[6];
for (int i = 1; i <= 5; i++)
{
dynamic untypedCustomer = new EdmEntityObject(customerType);
untypedCustomer.ID = i;
untypedCustomer.Name = string.Format("Name {0}", i);
untypedCustomer.SSN = "SSN-" + i + "-" + (100 + i);
untypedCustomers[i-1] = untypedCustomer;
}
// create a special customer for "PATCH"
dynamic customer = new EdmEntityObject(customerType);
customer.ID = 6;
customer.Name = "Name 6";
customer.SSN = "SSN-6-T-006";
untypedCustomers[5] = customer;
IEdmCollectionTypeReference entityCollectionType =
new EdmCollectionTypeReference(
new EdmCollectionType(
new EdmEntityTypeReference(customerType, isNullable: false)));
Customers = new EdmEntityObjectCollection(entityCollectionType, untypedCustomers.ToList());
}
开发者ID:chinadragon0515,项目名称:WebApi,代码行数:28,代码来源:AlternateKeysDataSource.cs
示例3: Init
public void Init()
{
EdmModel model = new EdmModel();
EdmComplexType complex1 = new EdmComplexType("ns", "complex1");
complex1.AddProperty(new EdmStructuralProperty(complex1, "p1", EdmCoreModel.Instance.GetInt32(isNullable: false)));
model.AddElement(complex1);
EdmComplexType complex2 = new EdmComplexType("ns", "complex2");
complex2.AddProperty(new EdmStructuralProperty(complex2, "p1", EdmCoreModel.Instance.GetInt32(isNullable: false)));
model.AddElement(complex2);
EdmComplexTypeReference complex2Reference = new EdmComplexTypeReference(complex2, isNullable: false);
EdmCollectionType primitiveCollectionType = new EdmCollectionType(EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int32, isNullable: false));
EdmCollectionType complexCollectionType = new EdmCollectionType(complex2Reference);
EdmCollectionTypeReference primitiveCollectionTypeReference = new EdmCollectionTypeReference(primitiveCollectionType);
EdmCollectionTypeReference complexCollectionTypeReference = new EdmCollectionTypeReference(complexCollectionType);
model.AddElement(new EdmTerm("custom", "int", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int32, isNullable: false)));
model.AddElement(new EdmTerm("custom", "string", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.String, isNullable: false)));
model.AddElement(new EdmTerm("custom", "double", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Double, isNullable: false)));
model.AddElement(new EdmTerm("custom", "bool", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: true)));
model.AddElement(new EdmTerm("custom", "decimal", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Decimal, isNullable: false)));
model.AddElement(new EdmTerm("custom", "timespan", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Duration, isNullable: false)));
model.AddElement(new EdmTerm("custom", "guid", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Guid, isNullable: false)));
model.AddElement(new EdmTerm("custom", "complex", complex2Reference));
model.AddElement(new EdmTerm("custom", "primitiveCollection", primitiveCollectionTypeReference));
model.AddElement(new EdmTerm("custom", "complexCollection", complexCollectionTypeReference));
this.stream = new MemoryStream();
this.settings = new ODataMessageWriterSettings { Version = ODataVersion.V4, ShouldIncludeAnnotation = ODataUtils.CreateAnnotationFilter("*") };
this.settings.SetServiceDocumentUri(ServiceDocumentUri);
this.serializer = new ODataAtomPropertyAndValueSerializer(this.CreateAtomOutputContext(model, this.stream));
}
开发者ID:rossjempson,项目名称:odata.net,代码行数:34,代码来源:ODataAtomPropertyAndValueSerializerTests.cs
示例4: NonPrimitiveIsXXXMethods
public void NonPrimitiveIsXXXMethods()
{
IEdmEntityType entityDef = new EdmEntityType("MyNamespace", "MyEntity");
IEdmEntityTypeReference entityRef = new EdmEntityTypeReference(entityDef, false);
Assert.IsTrue(entityRef.IsEntity(), "Entity is Entity");
IEdmPrimitiveTypeReference bad = entityRef.AsPrimitive();
Assert.IsTrue(bad.Definition.IsBad(), "bad TypeReference is bad");
Assert.AreEqual(EdmErrorCode.TypeSemanticsCouldNotConvertTypeReference, bad.Definition.Errors().First().ErrorCode, "Reference is bad from conversion");
Assert.IsTrue(bad.Definition.IsBad(), "Bad definition is bad");
Assert.AreEqual(EdmErrorCode.TypeSemanticsCouldNotConvertTypeReference, bad.Definition.Errors().First().ErrorCode, "Definition is bad from conversion");
IEdmPrimitiveType intDef = EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int32);
IEdmPrimitiveTypeReference intRef = new EdmPrimitiveTypeReference(intDef, false);
IEdmCollectionTypeReference intCollection = new EdmCollectionTypeReference(new EdmCollectionType(intRef));
Assert.IsTrue(intCollection.IsCollection(), "Collection is collection");
IEdmComplexType complexDef = new EdmComplexType("MyNamespace", "MyComplex");
IEdmComplexTypeReference complexRef = new EdmComplexTypeReference(complexDef, false);
Assert.IsTrue(complexRef.IsComplex(), "Complex is Complex");
Assert.IsTrue(entityRef.IsStructured(), "Entity is Structured");
Assert.IsTrue(complexRef.IsStructured(), "Complex is stuctured");
Assert.IsFalse(intCollection.IsStructured(), "Collection is not structured");
}
开发者ID:AlineGuan,项目名称:odata.net,代码行数:26,代码来源:TypeSemanticsUnitTests.cs
示例5: CollectionType_IsDeltaFeed_ReturnsFalseForNonDeltaCollectionType
public void CollectionType_IsDeltaFeed_ReturnsFalseForNonDeltaCollectionType()
{
IEdmEntityType _entityType = new EdmEntityType("NS", "Entity");
EdmCollectionType _edmType = new EdmCollectionType(new EdmEntityTypeReference(_entityType, isNullable: true));
IEdmCollectionTypeReference _edmTypeReference = new EdmCollectionTypeReference(_edmType);
Assert.False(_edmTypeReference.Definition.IsDeltaFeed());
}
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:8,代码来源:EdmTypeExtensionsTest.cs
示例6: GetEdmType_Returns_EdmTypeInitializedByCtor
public void GetEdmType_Returns_EdmTypeInitializedByCtor()
{
IEdmTypeReference elementType = new EdmEntityTypeReference(new EdmEntityType("NS", "Entity"), isNullable: false);
IEdmCollectionTypeReference collectionType = new EdmCollectionTypeReference(new EdmCollectionType(elementType));
var edmObject = new EdmEntityObjectCollection(collectionType);
Assert.Same(collectionType, edmObject.GetEdmType());
}
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:8,代码来源:EdmEntityCollectionObjectTest.cs
示例7: Ctor_ThrowsArgument_UnexpectedElementType
public void Ctor_ThrowsArgument_UnexpectedElementType()
{
IEdmTypeReference elementType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int32, isNullable: true);
IEdmCollectionTypeReference collectionType = new EdmCollectionTypeReference(new EdmCollectionType(elementType));
Assert.ThrowsArgument(() => new EdmEntityObjectCollection(collectionType), "edmType",
"The element type '[Edm.Int32 Nullable=True]' of the given collection type '[Collection([Edm.Int32 Nullable=True]) Nullable=True]' " +
"is not of the type 'IEdmEntityType'.");
}
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:9,代码来源:EdmEntityCollectionObjectTest.cs
示例8: Initialize
public void Initialize()
{
this.model = new EdmModel();
EdmComplexType personalInfo = new EdmComplexType(MyNameSpace, "PersonalInfo");
personalInfo.AddStructuralProperty("Age", EdmPrimitiveTypeKind.Int16);
personalInfo.AddStructuralProperty("Email", EdmPrimitiveTypeKind.String);
personalInfo.AddStructuralProperty("Tel", EdmPrimitiveTypeKind.String);
personalInfo.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Guid);
EdmComplexType derivedPersonalInfo = new EdmComplexType(MyNameSpace, "DerivedPersonalInfo", personalInfo);
derivedPersonalInfo.AddStructuralProperty("Hobby", EdmPrimitiveTypeKind.String);
EdmComplexType derivedDerivedPersonalInfo = new EdmComplexType(MyNameSpace, "DerivedDerivedPersonalInfo", derivedPersonalInfo);
derivedDerivedPersonalInfo.AddStructuralProperty("Education", EdmPrimitiveTypeKind.String);
EdmComplexType subjectInfo = new EdmComplexType(MyNameSpace, "Subject");
subjectInfo.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
subjectInfo.AddStructuralProperty("Score", EdmPrimitiveTypeKind.Int16);
EdmComplexType derivedSubjectInfo = new EdmComplexType(MyNameSpace, "DerivedSubject", subjectInfo);
derivedSubjectInfo.AddStructuralProperty("Teacher", EdmPrimitiveTypeKind.String);
EdmComplexType derivedDerivedSubjectInfo = new EdmComplexType(MyNameSpace, "DerivedDerivedSubject", derivedSubjectInfo);
derivedDerivedSubjectInfo.AddStructuralProperty("Classroom", EdmPrimitiveTypeKind.String);
EdmCollectionTypeReference subjectsCollection = new EdmCollectionTypeReference(new EdmCollectionType(new EdmComplexTypeReference(subjectInfo, isNullable: true)));
studentInfo = new EdmEntityType(MyNameSpace, "Student");
studentInfo.AddStructuralProperty("Info", new EdmComplexTypeReference(personalInfo, isNullable: false));
studentInfo.AddProperty(new EdmStructuralProperty(studentInfo, "Subjects", subjectsCollection));
// enum with flags
var enumFlagsType = new EdmEnumType(MyNameSpace, "ColorFlags", isFlags: true);
enumFlagsType.AddMember("Red", new EdmIntegerConstant(1));
enumFlagsType.AddMember("Green", new EdmIntegerConstant(2));
enumFlagsType.AddMember("Blue", new EdmIntegerConstant(4));
studentInfo.AddStructuralProperty("ClothesColors", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEnumTypeReference(enumFlagsType, true))));
EdmCollectionTypeReference hobbiesCollection = new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(isNullable: false)));
studentInfo.AddProperty(new EdmStructuralProperty(studentInfo, "Hobbies", hobbiesCollection));
model.AddElement(enumFlagsType);
model.AddElement(studentInfo);
model.AddElement(personalInfo);
model.AddElement(derivedPersonalInfo);
model.AddElement(derivedDerivedPersonalInfo);
model.AddElement(subjectInfo);
model.AddElement(derivedSubjectInfo);
model.AddElement(derivedDerivedSubjectInfo);
IEdmEntityContainer defaultContainer = new EdmEntityContainer("NS", "DefaultContainer");
model.AddElement(defaultContainer);
this.studentSet = new EdmEntitySet(defaultContainer, "MySet", this.studentInfo);
}
开发者ID:rossjempson,项目名称:odata.net,代码行数:56,代码来源:NonPrimitiveTypeRoundtripJsonLightTests.cs
示例9: GetEdmType_Returns_EdmTypeInitializedByCtor
public void GetEdmType_Returns_EdmTypeInitializedByCtor()
{
// Arrange
IEdmTypeReference elementType = new EdmEnumTypeReference(new EdmEnumType("NS", "Enum"), isNullable: false);
IEdmCollectionTypeReference collectionType = new EdmCollectionTypeReference(new EdmCollectionType(elementType));
// Act
var edmObject = new EdmEnumObjectCollection(collectionType);
// Assert
Assert.Same(collectionType, edmObject.GetEdmType());
}
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:12,代码来源:EdmEnumObjectCollectionTest.cs
示例10: ODataAtomAnnotationReaderTests
public ODataAtomAnnotationReaderTests()
{
this.model = new EdmModel();
this.model.AddElement(new EdmComplexType("foo", "complex"));
EdmComplexType complexType = new EdmComplexType("ns", "complex");
this.model.AddElement(complexType);
EdmComplexTypeReference complexTypeReference = new EdmComplexTypeReference(complexType, isNullable: false);
EdmCollectionType primitiveCollectionType = new EdmCollectionType(EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Guid, isNullable: false));
EdmCollectionType complexCollectionType = new EdmCollectionType(complexTypeReference);
EdmCollectionTypeReference primitiveCollectionTypeReference = new EdmCollectionTypeReference(primitiveCollectionType);
EdmCollectionTypeReference complexCollectionTypeReference = new EdmCollectionTypeReference(complexCollectionType);
this.model.AddElement(new EdmTerm("custom", "primitive", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Double, isNullable: false)));
this.model.AddElement(new EdmTerm("custom", "complex", complexTypeReference));
this.model.AddElement(new EdmTerm("custom", "primitiveCollection", primitiveCollectionTypeReference));
this.model.AddElement(new EdmTerm("custom", "complexCollection", complexCollectionTypeReference));
this.shouldIncludeAnnotation = (annotationName) => true;
}
开发者ID:larsenjo,项目名称:odata.net,代码行数:19,代码来源:ODataAtomAnnotationReaderTests.cs
示例11: AddUnboundAction
private static IEdmActionImport AddUnboundAction(EdmEntityContainer container, string name, IEdmEntityType bindingType, bool isCollection)
{
var action = new EdmAction(
container.Namespace, name, returnType: null, isBound: true, entitySetPathExpression: null);
IEdmTypeReference bindingParamterType = new EdmEntityTypeReference(bindingType, isNullable: false);
if (isCollection)
{
bindingParamterType = new EdmCollectionTypeReference(new EdmCollectionType(bindingParamterType));
}
action.AddParameter("bindingParameter", bindingParamterType);
var actionImport = container.AddActionImport(action);
return actionImport;
}
开发者ID:nicholaspei,项目名称:aspnetwebstack,代码行数:15,代码来源:DefaultODataPathHandlerTest.cs
示例12: FullPayloadValidateTests
static FullPayloadValidateTests()
{
EntityType = new EdmEntityType("Namespace", "EntityType", null, false, false, false);
EntityType.AddKeys(EntityType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32));
EntityType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(isNullable: true), null, EdmConcurrencyMode.Fixed);
DerivedType = new EdmEntityType("Namespace", "DerivedType", EntityType, false, true);
var expandedCollectionNavProp = EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
{
Target = EntityType,
TargetMultiplicity = EdmMultiplicity.Many,
Name = "ExpandedCollectionNavProp"
});
var expandedNavProp = EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
{
Target = EntityType,
TargetMultiplicity = EdmMultiplicity.One,
Name = "ExpandedNavProp"
});
EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
{
Target = EntityType,
TargetMultiplicity = EdmMultiplicity.Many,
Name = "ContainedCollectionNavProp",
ContainsTarget = true
});
EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
{
Target = EntityType,
TargetMultiplicity = EdmMultiplicity.One,
Name = "ContainedNavProp",
ContainsTarget = true
});
var container = new EdmEntityContainer("Namespace", "Container");
EntitySet = container.AddEntitySet("EntitySet", EntityType);
EntitySet.AddNavigationTarget(expandedNavProp, EntitySet);
EntitySet.AddNavigationTarget(expandedCollectionNavProp, EntitySet);
Model = new EdmModel();
Model.AddElement(EntityType);
Model.AddElement(DerivedType);
Model.AddElement(container);
ModelWithFunction = new EdmModel();
ModelWithFunction.AddElement(EntityType);
ModelWithFunction.AddElement(DerivedType);
ModelWithFunction.AddElement(container);
EdmEntityTypeReference entityTypeReference = new EdmEntityTypeReference(EntityType, false);
EdmCollectionTypeReference typeReference = new EdmCollectionTypeReference(new EdmCollectionType(entityTypeReference));
EdmFunction function = new EdmFunction("Namespace", "Function", EdmCoreModel.Instance.GetBoolean(true), true, null, false);
function.AddParameter("bindingParameter", typeReference);
ModelWithFunction.AddElement(function);
EdmAction action = new EdmAction("Namespace", "Action", EdmCoreModel.Instance.GetBoolean(true), true, null);
action.AddParameter("bindingParameter", typeReference);
ModelWithFunction.AddElement(action);
}
开发者ID:larsenjo,项目名称:odata.net,代码行数:63,代码来源:FullPayloadValidateTests.cs
示例13: BuildTableValueType
IEdmTypeReference BuildTableValueType(string name, EdmModel model)
{
EdmEntityContainer container = model.EntityContainer as EdmEntityContainer;
string spRtvTypeName = string.Format("{0}_RtvCollectionType", name);
EdmComplexType t = null;
t = new EdmComplexType("ns", spRtvTypeName);
using (DbAccess db = new DbAccess(this.ConnectionString))
{
db.ExecuteReader(this.TableValuedResultSetCommand, (reader) =>
{
var et = Utility.DBType2EdmType(reader["DATA_TYPE"].ToString());
if (et.HasValue)
{
string col = reader["COLUMN_NAME"].ToString();
t.AddStructuralProperty(col, et.Value, true);
}
}, (par) => { par.AddWithValue("@Name", name); });
}
var etr = new EdmComplexTypeReference(t, true);
var t1 = new EdmCollectionTypeReference(new EdmCollectionType(etr));
model.AddElement((t1.Definition as EdmCollectionType).ElementType.Definition as IEdmSchemaElement);
return t1;
}
开发者ID:maskx,项目名称:OData,代码行数:24,代码来源:SQLDataSource.cs
示例14: Term_Definition_Collection
public void Term_Definition_Collection()
{
this.SetupModels();
var definitionModel = new EdmModel();
var collectionOfInt16 = new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetInt16(false /*isNullable*/)));
var valueTermInt16 = new EdmTerm("NS2", "CollectionOfInt16", collectionOfInt16);
definitionModel.AddElement(valueTermInt16);
var collectionOfPerson = new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(this.baseModel.FindEntityType("NS1.Person"), true)));
var valueTermPerson = new EdmTerm("NS2", "CollectionOfPerson", collectionOfPerson);
definitionModel.AddElement(valueTermPerson);
string expectedCsdl =
@"<Schema Namespace=""NS2"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
<Term Name=""CollectionOfInt16"" Type=""Collection(Edm.Int16)"" Nullable=""false"" />
<Term Name=""CollectionOfPerson"" Type=""Collection(NS1.Person)"" />
</Schema>";
this.SerializeAndVerifyAgainst(definitionModel, expectedCsdl);
}
开发者ID:larsenjo,项目名称:odata.net,代码行数:20,代码来源:ExpressionSerializationTests.cs
示例15: ConvertCollectionValue
private static object ConvertCollectionValue(ODataCollectionValue collection,
ref IEdmTypeReference propertyType, ODataDeserializerProvider deserializerProvider,
ODataDeserializerContext readContext)
{
IEdmCollectionTypeReference collectionType;
if (propertyType == null)
{
// dynamic collection property
Contract.Assert(!String.IsNullOrEmpty(collection.TypeName),
"ODataLib should have verified that dynamic collection value has a type name " +
"since we provided metadata.");
string elementTypeName = GetCollectionElementTypeName(collection.TypeName, isNested: false);
IEdmModel model = readContext.Model;
IEdmSchemaType elementType = model.FindType(elementTypeName);
Contract.Assert(elementType != null);
collectionType =
new EdmCollectionTypeReference(
new EdmCollectionType(elementType.ToEdmTypeReference(isNullable: false)));
propertyType = collectionType;
}
else
{
collectionType = propertyType as IEdmCollectionTypeReference;
Contract.Assert(collectionType != null, "The type for collection must be a IEdmCollectionType.");
}
ODataEdmTypeDeserializer deserializer = deserializerProvider.GetEdmTypeDeserializer(collectionType);
return deserializer.ReadInline(collection, collectionType, readContext);
}
开发者ID:joshcomley,项目名称:WebApi,代码行数:30,代码来源:DeserializationHelpers.cs
示例16: BuildPeople
private static void BuildPeople(IEdmModel model)
{
IEdmEntityType personType = model.SchemaElements.OfType<IEdmEntityType>().First(e => e.Name == "Person");
IEdmEntityObject[] untypedPeople = new IEdmEntityObject[5];
for (int i = 0; i < 5; i++)
{
dynamic untypedPerson = new EdmEntityObject(personType);
untypedPerson.ID = i;
untypedPerson.Country = new[] { "Great Britain", "China", "United States", "Russia", "Japan" }[i];
untypedPerson.Passport = new[] { "1001", "2010", "9999", "3199992", "00001"}[i];
untypedPeople[i] = untypedPerson;
}
IEdmCollectionTypeReference entityCollectionType =
new EdmCollectionTypeReference(
new EdmCollectionType(
new EdmEntityTypeReference(personType, isNullable: false)));
People = new EdmEntityObjectCollection(entityCollectionType, untypedPeople.ToList());
}
开发者ID:chinadragon0515,项目名称:WebApi,代码行数:21,代码来源:AlternateKeysDataSource.cs
示例17: Get
public IHttpActionResult Get()
{
IEdmEntityObject[] untypedCustomers = new EdmEntityObject[20];
for (int i = 0; i < 20; i++)
{
dynamic untypedCustomer = new EdmEntityObject(CustomerType);
untypedCustomer.Id = i;
untypedCustomer.Name = string.Format("Name {0}", i);
untypedCustomer.Orders = CreateOrders(i);
untypedCustomer.Addresses = CreateAddresses(i);
untypedCustomer.FavoriteNumbers = Enumerable.Range(0, i).ToArray();
untypedCustomers[i] = untypedCustomer;
}
IEdmCollectionTypeReference entityCollectionType =
new EdmCollectionTypeReference(
new EdmCollectionType(
new EdmEntityTypeReference(CustomerType, isNullable: false)));
return Ok(new EdmEntityObjectCollection(entityCollectionType, untypedCustomers.ToList()));
}
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:21,代码来源:UntypedSerializationTests.cs
示例18: GetPropertyInitializationValueShouldReturnConstructorWithDataServiceCollectionConstructorParameters
public void GetPropertyInitializationValueShouldReturnConstructorWithDataServiceCollectionConstructorParameters()
{
EdmEntityType entityType = new EdmEntityType("Namespace", "elementName");
IEdmTypeReference elementTypeReference = new EdmTypeReferenceForTest(entityType, false);
IEdmCollectionType collectionType = new EdmCollectionType(elementTypeReference);
IEdmCollectionTypeReference collectionTypeReference = new EdmCollectionTypeReference(collectionType);
EdmPropertyForTest property = new EdmPropertyForTest(new EdmStructruedTypeForTest(), "propertyName", collectionTypeReference);
ODataT4CodeGenerator.Utils.GetPropertyInitializationValue(property, true, template, context).Should().Be("new global::Microsoft.OData.Client.DataServiceCollection<global::NamespacePrefix.elementName>(null, global::Microsoft.OData.Client.TrackingMode.None)");
}
开发者ID:TomDu,项目名称:odata.net,代码行数:9,代码来源:UtilsTests.cs
示例19: ApplyNavigationProperty_Calls_ReadInlineOnFeed
public void ApplyNavigationProperty_Calls_ReadInlineOnFeed()
{
// Arrange
IEdmCollectionTypeReference productsType = new EdmCollectionTypeReference(new EdmCollectionType(_productEdmType));
Mock<ODataEdmTypeDeserializer> productsDeserializer = new Mock<ODataEdmTypeDeserializer>(ODataPayloadKind.Feed);
Mock<ODataDeserializerProvider> deserializerProvider = new Mock<ODataDeserializerProvider>();
var deserializer = new ODataEntityDeserializer(deserializerProvider.Object);
ODataNavigationLinkWithItems navigationLink = new ODataNavigationLinkWithItems(new ODataNavigationLink { Name = "Products" });
navigationLink.NestedItems.Add(new ODataFeedWithEntries(new ODataFeed()));
Supplier supplier = new Supplier();
IEnumerable products = new[] { new Product { ID = 42 } };
deserializerProvider.Setup(d => d.GetEdmTypeDeserializer(It.IsAny<IEdmTypeReference>())).Returns(productsDeserializer.Object);
productsDeserializer
.Setup(d => d.ReadInline(navigationLink.NestedItems[0], _supplierEdmType.FindNavigationProperty("Products").Type, _readContext))
.Returns(products).Verifiable();
// Act
deserializer.ApplyNavigationProperty(supplier, navigationLink, _supplierEdmType, _readContext);
// Assert
productsDeserializer.Verify();
Assert.Equal(1, supplier.Products.Count());
Assert.Equal(42, supplier.Products.First().ID);
}
开发者ID:chinadragon0515,项目名称:WebApi,代码行数:26,代码来源:ODataEntityDeserializerTests.cs
示例20: CreateODataFeed_SetsNextPageLink_WhenWritingTruncatedCollection_ForExpandedProperties
public void CreateODataFeed_SetsNextPageLink_WhenWritingTruncatedCollection_ForExpandedProperties()
{
// Arrange
CustomersModelWithInheritance model = new CustomersModelWithInheritance();
IEdmCollectionTypeReference customersType = new EdmCollectionTypeReference(new EdmCollectionType(model.Customer.AsReference()));
ODataFeedSerializer serializer = new ODataFeedSerializer(new DefaultODataSerializerProvider());
SelectExpandClause selectExpandClause = new SelectExpandClause(new SelectItem[0], allSelected: true);
IEdmNavigationProperty ordersProperty = model.Customer.NavigationProperties().First();
EntityInstanceContext entity = new EntityInstanceContext
{
SerializerContext = new ODataSerializerContext { NavigationSource = model.Customers, Model = model.Model }
};
ODataSerializerContext nestedContext = new ODataSerializerContext(entity, selectExpandClause, ordersProperty);
TruncatedCollection<Order> orders = new TruncatedCollection<Order>(new[] { new Order(), new Order() }, pageSize: 1);
Mock<NavigationSourceLinkBuilderAnnotation> linkBuilder = new Mock<NavigationSourceLinkBuilderAnnotation>();
linkBuilder.Setup(l => l.BuildNavigationLink(entity, ordersProperty, ODataMetadataLevel.Default)).Returns(new Uri("http://navigation-link/"));
model.Model.SetNavigationSourceLinkBuilder(model.Customers, linkBuilder.Object);
model.Model.SetNavigationSourceLinkBuilder(model.Orders, new NavigationSourceLinkBuilderAnnotation());
// Act
ODataFeed feed = serializer.CreateODataFeed(orders, _customersType, nestedContext);
// Assert
Assert.Equal("http://navigation-link/?$skip=1", feed.NextPageLink.AbsoluteUri);
}
开发者ID:nicholaspei,项目名称:aspnetwebstack,代码行数:26,代码来源:ODataFeedSerializerTests.cs
注:本文中的Microsoft.OData.Edm.Library.EdmCollectionTypeReference类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论