本文整理汇总了C#中Microsoft.OData.Edm.Library.EdmModel.Validate方法的典型用法代码示例。如果您正苦于以下问题:C# EdmModel.Validate方法的具体用法?C# EdmModel.Validate怎么用?C# EdmModel.Validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.OData.Edm.Library.EdmModel
的用法示例。
在下文中一共展示了EdmModel.Validate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateModel
public static IEdmModel CreateModel(string ns)
{
EdmModel model = new EdmModel();
var defaultContainer = new EdmEntityContainer(ns, "DefaultContainer");
model.AddElement(defaultContainer);
var addressType = new EdmComplexType(ns, "Address");
addressType.AddProperty(new EdmStructuralProperty(addressType, "Road", EdmCoreModel.Instance.GetString(false)));
addressType.AddProperty(new EdmStructuralProperty(addressType, "City", EdmCoreModel.Instance.GetString(false)));
model.AddElement(addressType);
var personType = new EdmEntityType(ns, "Person");
var personIdProperty = new EdmStructuralProperty(personType, "PersonId", EdmCoreModel.Instance.GetInt32(false));
personType.AddProperty(personIdProperty);
personType.AddKeys(new IEdmStructuralProperty[] { personIdProperty });
personType.AddProperty(new EdmStructuralProperty(personType, "FirstName", EdmCoreModel.Instance.GetString(false)));
personType.AddProperty(new EdmStructuralProperty(personType, "LastName", EdmCoreModel.Instance.GetString(false)));
personType.AddProperty(new EdmStructuralProperty(personType, "Address", new EdmComplexTypeReference(addressType, true)));
personType.AddProperty(new EdmStructuralProperty(personType, "Descriptions", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(false)))));
model.AddElement(personType);
var peopleSet = new EdmEntitySet(defaultContainer, "People", personType);
defaultContainer.AddElement(peopleSet);
var numberComboType = new EdmComplexType(ns, "NumberCombo");
numberComboType.AddProperty(new EdmStructuralProperty(numberComboType, "Small", EdmCoreModel.Instance.GetInt32(false)));
numberComboType.AddProperty(new EdmStructuralProperty(numberComboType, "Middle", EdmCoreModel.Instance.GetInt64(false)));
numberComboType.AddProperty(new EdmStructuralProperty(numberComboType, "Large", EdmCoreModel.Instance.GetDecimal(false)));
model.AddElement(numberComboType);
var productType = new EdmEntityType(ns, "Product");
var productIdProperty = new EdmStructuralProperty(productType, "ProductId", EdmCoreModel.Instance.GetInt32(false));
productType.AddProperty(productIdProperty);
productType.AddKeys(new IEdmStructuralProperty[] { productIdProperty });
productType.AddProperty(new EdmStructuralProperty(productType, "Quantity", EdmCoreModel.Instance.GetInt64(false)));
productType.AddProperty(new EdmStructuralProperty(productType, "LifeTimeInSeconds", EdmCoreModel.Instance.GetDecimal(false)));
productType.AddProperty(new EdmStructuralProperty(productType, "TheCombo", new EdmComplexTypeReference(numberComboType, true)));
productType.AddProperty(new EdmStructuralProperty(productType, "LargeNumbers", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetDecimal(false)))));
model.AddElement(productType);
var productsSet = new EdmEntitySet(defaultContainer, "Products", productType);
defaultContainer.AddElement(productsSet);
var productsProperty = personType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
{
Name = "Products",
Target = productType,
TargetMultiplicity = EdmMultiplicity.Many
});
peopleSet.AddNavigationTarget(productsProperty, productsSet);
IEnumerable<EdmError> errors;
model.Validate(out errors);
return model;
}
示例2: ValidationShouldFailOnNonXmlValidAnnotationWhichWontBeSerialized
public void ValidationShouldFailOnNonXmlValidAnnotationWhichWontBeSerialized()
{
var model = new EdmModel();
var fredFlintstone = new EdmComplexType("Flintstones", "Fred");
fredFlintstone.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(false));
model.AddElement(fredFlintstone);
// Making the value of the annotation not an IEdmValue means that it won't be serialized out as an attribute annotation.
// We should still fail on this anyway, since being strict now has fewer consequences than trying to introduce strictness later.
model.SetAnnotationValue(fredFlintstone, "sap", "-content-version", 1);
Assert.AreEqual(1, model.DirectValueAnnotations(fredFlintstone).Count(), "Wrong # of Annotations on {0}.", fredFlintstone);
IEnumerable<EdmError> errors;
model.Validate(out errors);
Assert.AreEqual(1, errors.Count(), "Model expected to be invalid.");
EdmError error = errors.Single();
Assert.AreEqual(error.ErrorCode, EdmErrorCode.InvalidName, "Unexpected error code");
Assert.AreEqual(error.ErrorMessage, "The specified name is not allowed: '-content-version'.", "Unexpected error message");
}
示例3: ValidateOpenComplexTypeSupported
public void ValidateOpenComplexTypeSupported()
{
var ct = new StubEdmComplexType("NS1", "CT1")
{
IsOpen = true
};
ct.Add(new EdmStructuralProperty(ct, "p1", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int16, true)));
var model = new EdmModel();
model.AddElement(ct);
IEnumerable<EdmError> errors;
foreach (var v in new[] { Microsoft.OData.Edm.Library.EdmConstants.EdmVersionLatest })
{
model.SetEdmVersion(v);
model.Validate(out errors);
Assert.AreEqual(0, errors.Count(), "No error should be returned");
}
}
示例4: AnnotationNameWhichIsNotSimpleIdentifierShouldPassValidation
public void AnnotationNameWhichIsNotSimpleIdentifierShouldPassValidation()
{
var model = new EdmModel();
model.SetEdmVersion(Microsoft.OData.Edm.Library.EdmConstants.EdmVersion4);
var fredFlintstone = new EdmComplexType("Flintstones", "Fred");
fredFlintstone.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(false));
model.AddElement(fredFlintstone);
// set the annotation name to a value which is valid XML, but not a valid SimpleIdentifier.
model.SetAnnotationValue(fredFlintstone, "sap", "content-version", new EdmStringConstant(EdmCoreModel.Instance.GetString(false), "hello"));
Assert.AreEqual(1, model.DirectValueAnnotations(fredFlintstone).Count(), "Wrong # of Annotations on {0}.", fredFlintstone);
IEnumerable<EdmError> errors;
model.Validate(out errors);
Assert.AreEqual(0, errors.Count(), "Model expected to be valid.");
}
示例5: ValidationShouldFailOnNonXmlValidAnnotation
public void ValidationShouldFailOnNonXmlValidAnnotation()
{
var model = new EdmModel();
var fredFlintstone = new EdmComplexType("Flintstones", "Fred");
fredFlintstone.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(false));
model.AddElement(fredFlintstone);
// Set annnotation which would be serialized as an attribute to be a value that is invalid per the xml spec.
model.SetAnnotationValue(fredFlintstone, "sap", "-content-version", new EdmStringConstant(EdmCoreModel.Instance.GetString(false), "hello"));
Assert.AreEqual(1, model.DirectValueAnnotations(fredFlintstone).Count(), "Wrong # of Annotations on {0}.", fredFlintstone);
IEnumerable<EdmError> errors;
model.Validate(out errors);
Assert.AreEqual(1, errors.Count(), "Model expected to be invalid.");
EdmError error = errors.Single();
Assert.AreEqual(error.ErrorCode, EdmErrorCode.InvalidName, "Unexpected error code");
Assert.AreEqual(error.ErrorMessage, "The specified name is not allowed: '-content-version'.", "Unexpected error message");
}
示例6: OneWayNavigationPropertyMultipleMappingTest
public void OneWayNavigationPropertyMultipleMappingTest()
{
EdmModel model = new EdmModel();
EdmEntityType t3 = new EdmEntityType("Bunk", "T3");
EdmStructuralProperty f31 = t3.AddStructuralProperty("F31", EdmCoreModel.Instance.GetString(false));
t3.AddKeys(f31);
model.AddElement(t3);
EdmEntityType t1 = new EdmEntityType("Bunk", "T1");
EdmStructuralProperty f11 = t1.AddStructuralProperty("F11", EdmCoreModel.Instance.GetString(false));
t1.AddKeys(f11);
EdmNavigationProperty p101 = t1.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "P101", Target = t3, TargetMultiplicity = EdmMultiplicity.One });
model.AddElement(t1);
EdmEntityContainer c1 = new EdmEntityContainer("Bunk", "Gunk");
EdmEntitySet E1a = c1.AddEntitySet("E1a", t1);
EdmEntitySet E1b = c1.AddEntitySet("E1b", t1);
EdmEntitySet E3 = c1.AddEntitySet("E3", t3);
E1a.AddNavigationTarget(p101, E3);
E1b.AddNavigationTarget(p101, E3);
model.AddElement(c1);
IEnumerable<EdmError> edmErrors;
model.Validate(out edmErrors);
Assert.IsTrue(!edmErrors.Any(), @"Enable multiple mappings for the same (silent) navigation property");
this.GetParserResult(this.GetSerializerResult(model)).Validate(out edmErrors);
Assert.IsTrue(!edmErrors.Any(), @"Enable multiple mappings for the same (silent) navigation property");
}
示例7: TwoWayNavigationPropertyMultipleMappingInSingletonTest
public void TwoWayNavigationPropertyMultipleMappingInSingletonTest()
{
var model = new EdmModel();
var t3 = new EdmEntityType("Bunk", "T3");
var f31 = t3.AddStructuralProperty("F31", EdmCoreModel.Instance.GetString(false));
t3.AddKeys(f31);
model.AddElement(t3);
var t1 = new EdmEntityType("Bunk", "T1");
var f11 = t1.AddStructuralProperty("F11", EdmCoreModel.Instance.GetString(false));
t1.AddKeys(f11);
var p101 = t1.AddBidirectionalNavigation
(
new EdmNavigationPropertyInfo() { Name = "P101", Target = t3, TargetMultiplicity = EdmMultiplicity.One },
new EdmNavigationPropertyInfo() { Name = "P301", TargetMultiplicity = EdmMultiplicity.One }
);
model.AddElement(t1);
var c1 = new EdmEntityContainer("Bunk", "Gunk");
var E1a = c1.AddEntitySet("E1a", t1);
var E1b = c1.AddSingleton("E1b", t1);
var E3 = c1.AddSingleton("E3", t3);
E1a.AddNavigationTarget(p101, E3);
E1b.AddNavigationTarget(p101, E3);
E3.AddNavigationTarget(p101.Partner, E1a);
model.AddElement(c1);
var expectedErrors = new EdmLibTestErrors()
{
{ "(Microsoft.OData.Edm.Library.EdmSingleton)", EdmErrorCode.NavigationMappingMustBeBidirectional },
};
IEnumerable<EdmError> edmErrors;
model.Validate(out edmErrors);
this.CompareErrors(edmErrors, expectedErrors);
}
示例8: CreateModel
public static IEdmModel CreateModel(string ns)
{
EdmModel model = new EdmModel();
var defaultContainer = new EdmEntityContainer(ns, "DefaultContainer");
model.AddElement(defaultContainer);
var nameType = new EdmTypeDefinition(ns, "Name", EdmPrimitiveTypeKind.String);
model.AddElement(nameType);
var addressType = new EdmComplexType(ns, "Address");
addressType.AddProperty(new EdmStructuralProperty(addressType, "Road", new EdmTypeDefinitionReference(nameType, false)));
addressType.AddProperty(new EdmStructuralProperty(addressType, "City", EdmCoreModel.Instance.GetString(false)));
model.AddElement(addressType);
var personType = new EdmEntityType(ns, "Person");
var personIdProperty = new EdmStructuralProperty(personType, "PersonId", EdmCoreModel.Instance.GetInt32(false));
personType.AddProperty(personIdProperty);
personType.AddKeys(new IEdmStructuralProperty[] { personIdProperty });
personType.AddProperty(new EdmStructuralProperty(personType, "FirstName", new EdmTypeDefinitionReference(nameType, false)));
personType.AddProperty(new EdmStructuralProperty(personType, "LastName", new EdmTypeDefinitionReference(nameType, false)));
personType.AddProperty(new EdmStructuralProperty(personType, "Address", new EdmComplexTypeReference(addressType, true)));
personType.AddProperty(new EdmStructuralProperty(personType, "Descriptions", new EdmCollectionTypeReference(new EdmCollectionType(new EdmTypeDefinitionReference(nameType, false)))));
model.AddElement(personType);
var peopleSet = new EdmEntitySet(defaultContainer, "People", personType);
defaultContainer.AddElement(peopleSet);
var numberComboType = new EdmComplexType(ns, "NumberCombo");
numberComboType.AddProperty(new EdmStructuralProperty(numberComboType, "Small", model.GetUInt16(ns, false)));
numberComboType.AddProperty(new EdmStructuralProperty(numberComboType, "Middle", model.GetUInt32(ns, false)));
numberComboType.AddProperty(new EdmStructuralProperty(numberComboType, "Large", model.GetUInt64(ns, false)));
model.AddElement(numberComboType);
var productType = new EdmEntityType(ns, "Product");
var productIdProperty = new EdmStructuralProperty(productType, "ProductId", model.GetUInt16(ns, false));
productType.AddProperty(productIdProperty);
productType.AddKeys(new IEdmStructuralProperty[] { productIdProperty });
productType.AddProperty(new EdmStructuralProperty(productType, "Quantity", model.GetUInt32(ns, false)));
productType.AddProperty(new EdmStructuralProperty(productType, "NullableUInt32", model.GetUInt32(ns, true)));
productType.AddProperty(new EdmStructuralProperty(productType, "LifeTimeInSeconds", model.GetUInt64(ns, false)));
productType.AddProperty(new EdmStructuralProperty(productType, "TheCombo", new EdmComplexTypeReference(numberComboType, true)));
productType.AddProperty(new EdmStructuralProperty(productType, "LargeNumbers", new EdmCollectionTypeReference(new EdmCollectionType(model.GetUInt64(ns, false)))));
model.AddElement(productType);
var productsSet = new EdmEntitySet(defaultContainer, "Products", productType);
defaultContainer.AddElement(productsSet);
//Bound Function: bound to entity, return defined type
var getFullNameFunction = new EdmFunction(ns, "GetFullName", new EdmTypeDefinitionReference(nameType, false), true, null, false);
getFullNameFunction.AddParameter("person", new EdmEntityTypeReference(personType, false));
getFullNameFunction.AddParameter("nickname", new EdmTypeDefinitionReference(nameType, false));
model.AddElement(getFullNameFunction);
//Bound Action: bound to entity, return UInt64
var extendLifeTimeAction = new EdmAction(ns, "ExtendLifeTime", model.GetUInt64(ns, false), true, null);
extendLifeTimeAction.AddParameter("product", new EdmEntityTypeReference(productType, false));
extendLifeTimeAction.AddParameter("seconds", model.GetUInt32(ns, false));
model.AddElement(extendLifeTimeAction);
//UnBound Action: ResetDataSource
var resetDataSourceAction = new EdmAction(ns, "ResetDataSource", null, false, null);
model.AddElement(resetDataSourceAction);
defaultContainer.AddActionImport(resetDataSourceAction);
IEnumerable<EdmError> errors = null;
model.Validate(out errors);
return model;
}
示例9: VerifyValidatorForNullError
public void VerifyValidatorForNullError()
{
EdmModel model = new EdmModel();
model.AddElement(new ValidationTestModelBuilder.TestEdmAssociatedCheckableNullErrorElement());
IEnumerable<EdmError> edmError = null;
model.Validate(out edmError);
Assert.IsFalse(edmError.Any(), "The number of EdmErrors should be 0 if the null Error case means no error.");
}
示例10: CreateODataServiceModel
//.........这里部分代码省略.........
getAccountInfoFunction.AddParameter("account", new EdmEntityTypeReference(accountType, false));
model.AddElement(getAccountInfoFunction);
#endregion
var accountGiftCardNavigation = accountType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
{
Name = "MyGiftCard",
Target = giftCardType,
TargetMultiplicity = EdmMultiplicity.ZeroOrOne,
ContainsTarget = true
});
var accountPIsNavigation = accountType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
{
Name = "MyPaymentInstruments",
Target = paymentInstrumentType,
TargetMultiplicity = EdmMultiplicity.Many,
ContainsTarget = true
});
var accountActiveSubsNavigation = accountType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
{
Name = "ActiveSubscriptions",
Target = subscriptionType,
TargetMultiplicity = EdmMultiplicity.Many,
ContainsTarget = true
});
var accountAvailableSubsTemplatesNavigation = accountType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
{
Name = "AvailableSubscriptionTemplatess",
Target = subscriptionType,
TargetMultiplicity = EdmMultiplicity.Many,
ContainsTarget = false
});
var piStoredNavigation = paymentInstrumentType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
{
Name = "TheStoredPI",
Target = storedPIType,
TargetMultiplicity = EdmMultiplicity.One,
ContainsTarget = false
});
var piStatementsNavigation = paymentInstrumentType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
{
Name = "BillingStatements",
Target = statementType,
TargetMultiplicity = EdmMultiplicity.Many,
ContainsTarget = true
});
var piBackupStoredPINavigation = paymentInstrumentType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
{
Name = "BackupStoredPI",
Target = storedPIType,
TargetMultiplicity = EdmMultiplicity.One,
ContainsTarget = false
});
var creditCardCreditRecordNavigation = creditCardType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
{
Name = "CreditRecords",
Target = creditRecordType,
TargetMultiplicity = EdmMultiplicity.Many,
ContainsTarget = true
});
model.AddElement(accountInfoType);
model.AddElement(accountType);
model.AddElement(giftCardType);
model.AddElement(paymentInstrumentType);
model.AddElement(creditCardType);
model.AddElement(storedPIType);
model.AddElement(statementType);
model.AddElement(creditRecordType);
model.AddElement(subscriptionType);
var accountSet = new EdmEntitySet(defaultContainer, "Accounts", accountType);
defaultContainer.AddElement(accountSet);
var storedPISet = new EdmEntitySet(defaultContainer, "StoredPIs", storedPIType);
defaultContainer.AddElement(storedPISet);
var subscriptionTemplatesSet = new EdmEntitySet(defaultContainer, "SubscriptionTemplates", subscriptionType);
defaultContainer.AddElement(subscriptionTemplatesSet);
var defaultStoredPI = new EdmSingleton(defaultContainer, "DefaultStoredPI", storedPIType);
defaultContainer.AddElement(defaultStoredPI);
((EdmEntitySet)accountSet).AddNavigationTarget(piStoredNavigation, storedPISet);
((EdmEntitySet)accountSet).AddNavigationTarget(accountAvailableSubsTemplatesNavigation, subscriptionTemplatesSet);
((EdmEntitySet)accountSet).AddNavigationTarget(piBackupStoredPINavigation, defaultStoredPI);
#endregion
IEnumerable<EdmError> errors = null;
model.Validate(out errors);
//TODO: Fix the errors
return model;
}
示例11: CreateModel
public static IEdmModel CreateModel(string ns)
{
EdmModel model = new EdmModel();
var defaultContainer = new EdmEntityContainer(ns, "DefaultContainer");
model.AddElement(defaultContainer);
var orderDetail = new EdmComplexType(ns, "orderDetail");
orderDetail.AddProperty(new EdmStructuralProperty(orderDetail, "amount", EdmCoreModel.Instance.GetDecimal(false)));
orderDetail.AddProperty(new EdmStructuralProperty(orderDetail, "quantity", EdmCoreModel.Instance.GetInt32(false)));
model.AddElement(orderDetail);
var billingType = new EdmEnumType(ns, "billingType", EdmPrimitiveTypeKind.Int64, false);
billingType.AddMember("fund", new EdmIntegerConstant(0));
billingType.AddMember("refund", new EdmIntegerConstant(1));
billingType.AddMember("chargeback", new EdmIntegerConstant(2));
model.AddElement(billingType);
var category = new EdmEnumType(ns, "category", true);
category.AddMember("toy", new EdmIntegerConstant(1));
category.AddMember("food", new EdmIntegerConstant(2));
category.AddMember("cloth", new EdmIntegerConstant(4));
category.AddMember("drink", new EdmIntegerConstant(8));
category.AddMember("computer", new EdmIntegerConstant(16));
model.AddElement(category);
var namedObject = new EdmEntityType(ns, "namedObject");
var idProperty = new EdmStructuralProperty(namedObject, "id", EdmCoreModel.Instance.GetInt32(false));
namedObject.AddProperty(idProperty);
namedObject.AddKeys(idProperty);
namedObject.AddProperty(new EdmStructuralProperty(namedObject, "name", EdmCoreModel.Instance.GetString(false)));
model.AddElement(namedObject);
var order = new EdmEntityType(ns, "order", namedObject);
order.AddProperty(new EdmStructuralProperty(order, "description", EdmCoreModel.Instance.GetString(false)));
order.AddProperty(new EdmStructuralProperty(order, "detail", new EdmComplexTypeReference(orderDetail, true)));
order.AddProperty(new EdmStructuralProperty(order, "lineItems",
new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(false)))));
order.AddProperty(new EdmStructuralProperty(order, "categories", new EdmEnumTypeReference(category, false)));
model.AddElement(order);
var billingRecord = new EdmEntityType(ns, "billingRecord", namedObject);
billingRecord.AddProperty(new EdmStructuralProperty(billingRecord, "amount", EdmCoreModel.Instance.GetDecimal(false)));
billingRecord.AddProperty(new EdmStructuralProperty(billingRecord, "type", new EdmEnumTypeReference(billingType, false)));
model.AddElement(billingRecord);
var store = new EdmEntityType(ns, "store", namedObject);
store.AddProperty(new EdmStructuralProperty(store, "address", EdmCoreModel.Instance.GetString(false)));
model.AddElement(store);
var orders = new EdmEntitySet(defaultContainer, "orders", order);
defaultContainer.AddElement(orders);
var billingRecords = new EdmEntitySet(defaultContainer, "billingRecords", billingRecord);
defaultContainer.AddElement(billingRecords);
var myStore = new EdmSingleton(defaultContainer, "myStore", store);
defaultContainer.AddElement(myStore);
var order2billingRecord = order.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
{
Name = "billingRecords",
Target = billingRecord,
TargetMultiplicity = EdmMultiplicity.Many
});
((EdmEntitySet)orders).AddNavigationTarget(order2billingRecord, billingRecords);
IEnumerable<EdmError> errors = null;
model.Validate(out errors);
return model;
}
示例12: TestEnumMemberReferencingExtraEnumType
public void TestEnumMemberReferencingExtraEnumType()
{
const string csdl = @"<?xml version=""1.0"" encoding=""utf-8""?>
<edmx:Edmx Version=""4.0"" xmlns:edmx=""http://docs.oasis-open.org/odata/ns/edmx"">
<edmx:DataServices>
<Schema Namespace=""TestNS"" 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=""Name"" Type=""Edm.String"" />
<Annotation Term=""TestNS.OutColor"">
<EnumMember>TestNS2.Color/Blue TestNS2.Color/Cyan</EnumMember>
</Annotation>
</EntityType>
<Term Name=""OutColor"" Type=""TestNS2.Color"" />
</Schema>
<Schema Namespace=""TestNS2"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
<EnumType Name=""Color"" IsFlags=""true"">
<Member Name=""Cyan"" Value=""1"" />
<Member Name=""Blue"" Value=""2"" />
</EnumType>
</Schema>
</edmx:DataServices>
</edmx:Edmx>";
IEdmModel model;
IEnumerable<EdmError> errors;
IEnumerable<EdmError> validationErrors;
#region try build model
var edmModel = new EdmModel();
var personType = new EdmEntityType("TestNS", "Person");
edmModel.AddElement(personType);
var pid = personType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32, false);
personType.AddKeys(pid);
personType.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
var colorType = new EdmEnumType("TestNS2", "Color", true);
edmModel.AddElement(colorType);
colorType.AddMember("Cyan", new EdmIntegerConstant(1));
colorType.AddMember("Blue", new EdmIntegerConstant(2));
var outColorTerm = new EdmTerm("TestNS", "OutColor", new EdmEnumTypeReference(colorType, true));
edmModel.AddElement(outColorTerm);
var exp = new EdmEnumMemberExpression(
new EdmEnumMember(colorType, "Blue", new EdmIntegerConstant(2)),
new EdmEnumMember(colorType, "Cyan", new EdmIntegerConstant(1))
);
var annotation = new EdmAnnotation(personType, outColorTerm, exp);
annotation.SetSerializationLocation(edmModel, EdmVocabularyAnnotationSerializationLocation.Inline);
edmModel.SetVocabularyAnnotation(annotation);
var stream = new MemoryStream();
Assert.IsFalse(edmModel.Validate(out errors));
using (var xw = XmlWriter.Create(stream, new XmlWriterSettings() { Indent = true }))
{
Assert.IsTrue(EdmxWriter.TryWriteEdmx(edmModel, xw, EdmxTarget.OData, out errors));
}
stream.Seek(0, SeekOrigin.Begin);
using (var sr = new StreamReader(stream))
{
Assert.AreEqual(csdl, sr.ReadToEnd());
}
#endregion
Assert.IsTrue(EdmxReader.TryParse(XmlReader.Create(new StringReader(csdl)), out model, out errors), "parsed");
Assert.IsFalse(model.Validate(out validationErrors));
TestEnumMember(model);
}
示例13: TestEdmValidator
public void TestEdmValidator()
{
var model = new EdmModel();
IEnumerable<EdmError> actualErrors;
model.Validate(out actualErrors);
Assert.AreEqual(0, actualErrors.Count(), "Invalid error count.");
this.VerifyThrowsException(typeof(ArgumentNullException), () => model.Validate((ValidationRuleSet)null, out actualErrors));
this.VerifyThrowsException(typeof(ArgumentNullException), () => model.Validate(new ValidationRuleSet(null), out actualErrors));
model.Validate(new ValidationRuleSet(new List<ValidationRule>()), out actualErrors);
Assert.AreEqual(0, actualErrors.Count(), "Invalid error count.");
}
示例14: CreateODataServiceModel
//.........这里部分代码省略.........
var stringCollectionTypeReference =
new EdmCollectionTypeReference(new EdmCollectionType(stringTypeReference));
var orderTypeReference = new EdmEntityTypeReference(orderType, true);
var orderCollectionTypeReference =
new EdmCollectionTypeReference(new EdmCollectionType(orderTypeReference));
//Bound Function : Bound to Collection Of Entity, Parameter is Complex Value, Return Entity.
var getCustomerForAddressFunction = new EdmFunction(ns, "GetCustomerForAddress", customerTypeReference, true, new EdmPathExpression("customers"), true);
getCustomerForAddressFunction.AddParameter("customers", customerCollectionTypeReference);
getCustomerForAddressFunction.AddParameter("address", addressTypeReference);
model.AddElement(getCustomerForAddressFunction);
//Bound Function : Bound to Collection Of Entity, Parameter is Collection of Complex Value, Return Collection Of Entity.
var getCustomersForAddressesFunction = new EdmFunction(ns, "GetCustomersForAddresses", customerCollectionTypeReference, true, new EdmPathExpression("customers"), true);
getCustomersForAddressesFunction.AddParameter("customers", customerCollectionTypeReference);
getCustomersForAddressesFunction.AddParameter("addresses", addressCollectionTypeRefernce);
model.AddElement(getCustomersForAddressesFunction);
//Bound Function : Bound to Collection Of Entity, Parameter is Collection of Complex Value, Return Entity
var getCustomerForAddressesFunction = new EdmFunction(ns, "GetCustomerForAddresses", customerTypeReference, true, new EdmPathExpression("customers"), true);
getCustomerForAddressesFunction.AddParameter("customers", customerCollectionTypeReference);
getCustomerForAddressesFunction.AddParameter("addresses", addressCollectionTypeRefernce);
model.AddElement(getCustomerForAddressesFunction);
//Bound Function : Bound to Entity, Return Complex Value
var getCustomerAddressFunction = new EdmFunction(ns, "GetCustomerAddress", addressTypeReference, true, null, true);
getCustomerAddressFunction.AddParameter("customer", customerTypeReference);
model.AddElement(getCustomerAddressFunction);
//Bound Function : Bound to Entity, Parameter is Complex Value, Return Entity
var verifyCustomerAddressFunction = new EdmFunction(ns, "VerifyCustomerAddress", customerTypeReference, true, new EdmPathExpression("customer"), true);
verifyCustomerAddressFunction.AddParameter("customer", customerTypeReference);
verifyCustomerAddressFunction.AddParameter("addresses", addressTypeReference);
model.AddElement(verifyCustomerAddressFunction);
//Bound Function : Bound to Entity, Parameter is Entity, Return Entity
var verifyCustomerByOrderFunction = new EdmFunction(ns, "VerifyCustomerByOrder", customerTypeReference, true, new EdmPathExpression("customer"), true);
verifyCustomerByOrderFunction.AddParameter("customer", customerTypeReference);
verifyCustomerByOrderFunction.AddParameter("order", orderTypeReference);
model.AddElement(verifyCustomerByOrderFunction);
//Bound Function : Bound to Entity, Parameter is Collection of String, Return Collection of Entity
var getOrdersFromCustomerByNotesFunction = new EdmFunction(ns, "GetOrdersFromCustomerByNotes", orderCollectionTypeReference, true, new EdmPathExpression("customer/Orders"), true);
getOrdersFromCustomerByNotesFunction.AddParameter("customer", customerTypeReference);
getOrdersFromCustomerByNotesFunction.AddParameter("notes", stringCollectionTypeReference);
model.AddElement(getOrdersFromCustomerByNotesFunction);
//Bound Function : Bound to Collection Of Entity, Parameter is String, Return Collection of Entity
var getOrdersByNoteFunction = new EdmFunction(ns, "GetOrdersByNote", orderCollectionTypeReference, true, new EdmPathExpression("orders"), true);
getOrdersByNoteFunction.AddParameter("orders", orderCollectionTypeReference);
getOrdersByNoteFunction.AddParameter("note", stringTypeReference);
model.AddElement(getOrdersByNoteFunction);
//Bound Function : Bound to Collection Of Entity, Parameter is Collection of String, Return Entity
var getOrderByNoteFunction = new EdmFunction(ns, "GetOrderByNote", orderTypeReference, true, new EdmPathExpression("orders"), true);
getOrderByNoteFunction.AddParameter("orders", orderCollectionTypeReference);
getOrderByNoteFunction.AddParameter("notes", stringCollectionTypeReference);
model.AddElement(getOrderByNoteFunction);
//Bound Function : Bound to Collection Of Entity, Parameter is Collection of Entity, Return Collection Of Entity
var getCustomersByOrdersFunction = new EdmFunction(ns, "GetCustomersByOrders", customerCollectionTypeReference, true, new EdmPathExpression("customers"), true);
getCustomersByOrdersFunction.AddParameter("customers", customerCollectionTypeReference);
getCustomersByOrdersFunction.AddParameter("orders", orderCollectionTypeReference);
model.AddElement(getCustomersByOrdersFunction);
//Bound Function : Bound to Collection Of Entity, Parameter is Entity, Return Entity
var getCustomerByOrderFunction = new EdmFunction(ns, "GetCustomerByOrder", customerTypeReference, true, new EdmPathExpression("customers"), true);
getCustomerByOrderFunction.AddParameter("customers", customerCollectionTypeReference);
getCustomerByOrderFunction.AddParameter("order", orderTypeReference);
model.AddElement(getCustomerByOrderFunction);
// Function Import: Parameter is Collection of Entity, Return Collection Of Entity
var getCustomersByOrdersUnboundFunction = new EdmFunction(ns, "GetCustomersByOrders", customerCollectionTypeReference, false, null, true);
getCustomersByOrdersUnboundFunction.AddParameter("orders", orderCollectionTypeReference);
model.AddElement(getCustomersByOrdersUnboundFunction);
defaultContainer.AddFunctionImport(getCustomersByOrdersUnboundFunction.Name, getCustomersByOrdersUnboundFunction, new EdmEntitySetReferenceExpression(customerSet));
// Function Import: Parameter is Collection of Entity, Return Entity
var getCustomerByOrderUnboundFunction = new EdmFunction(ns, "GetCustomerByOrder", customerTypeReference, false, null, true);
getCustomerByOrderUnboundFunction.AddParameter("order", orderTypeReference);
model.AddElement(getCustomerByOrderUnboundFunction);
defaultContainer.AddFunctionImport(getCustomerByOrderUnboundFunction.Name, getCustomerByOrderUnboundFunction, new EdmEntitySetReferenceExpression(customerSet));
// Function Import: Bound to Entity, Return Complex Value
var getCustomerAddressUnboundFunction = new EdmFunction(ns, "GetCustomerAddress", addressTypeReference, false, null, true);
getCustomerAddressUnboundFunction.AddParameter("customer", customerTypeReference);
model.AddElement(getCustomerAddressUnboundFunction);
defaultContainer.AddFunctionImport(getCustomerAddressUnboundFunction.Name, getCustomerAddressUnboundFunction);
#endregion
IEnumerable<EdmError> errors;
model.Validate(out errors);
if (errors.Any())
{
throw new SystemException("The model is not valid, please correct it");
}
return model;
}
示例15: CreateModelWithSillyNamespace
private EdmModel CreateModelWithSillyNamespace()
{
var model = new EdmModel();
var customer = new EdmEntityType("Really.Way.Too.Long.Namespace.With.Lots.Of.Dots", "Customer");
var customerId = customer.AddStructuralProperty("CustomerID", EdmCoreModel.Instance.GetString(false));
customer.AddKeys(customerId);
model.AddElement(customer);
var title = new EdmTerm("Really.Way.Too.Long.Namespace.With.Lots.Of.Dots", "Title", EdmCoreModel.Instance.GetString(true));
model.AddElement(title);
var integerId = new EdmTerm("Really.Way.Too.Long.Namespace.With.Lots.Of.Dots", "integerId", EdmCoreModel.Instance.GetString(true));
model.AddElement(integerId);
var person = new EdmEntityType("Really.Way.Too.Long.Namespace.With.Lots.Of.Dots", "Person");
var Id = person.AddStructuralProperty("ID", EdmCoreModel.Instance.GetString(false));
person.AddKeys(Id);
model.AddElement(person);
var container = new EdmEntityContainer("Really.Way.Too.Long.Namespace.With.Lots.Of.Dots", "Container");
container.AddEntitySet("Customers", customer);
model.AddElement(container);
IEnumerable<EdmError> errors;
Assert.IsTrue(model.Validate(out errors), "validate");
return model;
}