本文整理汇总了C#中Microsoft.OData.Edm.Library.EdmModel类的典型用法代码示例。如果您正苦于以下问题:C# EdmModel类的具体用法?C# EdmModel怎么用?C# EdmModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EdmModel类属于Microsoft.OData.Edm.Library命名空间,在下文中一共展示了EdmModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetModel
public void GetModel(EdmModel model, EdmEntityContainer container)
{
EdmEntityType student = new EdmEntityType("ns", "Student");
student.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
EdmStructuralProperty key = student.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32);
student.AddKeys(key);
model.AddElement(student);
EdmEntitySet students = container.AddEntitySet("Students", student);
EdmEntityType school = new EdmEntityType("ns", "School");
school.AddKeys(school.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32));
school.AddStructuralProperty("CreatedDay", EdmPrimitiveTypeKind.DateTimeOffset);
model.AddElement(school);
EdmEntitySet schools = container.AddEntitySet("Schools", student);
EdmNavigationProperty schoolNavProp = student.AddUnidirectionalNavigation(
new EdmNavigationPropertyInfo
{
Name = "School",
TargetMultiplicity = EdmMultiplicity.One,
Target = school
});
students.AddNavigationTarget(schoolNavProp, schools);
_school = school;
}
示例2: ODataAtomPropertyAndValueDeserializerTests
static ODataAtomPropertyAndValueDeserializerTests()
{
EdmModel = new EdmModel();
ComplexType = new EdmComplexType("TestNamespace", "TestComplexType");
StringProperty = ComplexType.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
EdmModel.AddElement(ComplexType);
}
示例3: SQLDataSource
public SQLDataSource(string name, string connectionString,
Func<MethodType, string, bool> permissionCheck = null,
string modelCommand = "GetEdmModelInfo",
string funcCommand = "GetEdmSPInfo",
string tvfCommand = "GetEdmTVFInfo",
string relationCommand = "GetEdmRelationship",
string storedProcedureResultSetCommand = "GetEdmSPResultSet",
string userDefinedTableCommand = "GetEdmUDTInfo",
string tableValuedResultSetCommand = "GetEdmTVFResultSet")
{
this.Name = name;
this.ConnectionString = connectionString;
this.PermissionCheck = permissionCheck;
_Model = new Lazy<EdmModel>(() =>
{
ModelCommand = modelCommand;
FuncCommand = funcCommand;
TableValuedCommand = tvfCommand;
RelationCommand = relationCommand;
StoredProcedureResultSetCommand = storedProcedureResultSetCommand;
UserDefinedTableCommand = userDefinedTableCommand;
TableValuedResultSetCommand = tableValuedResultSetCommand;
var model = new EdmModel();
var container = new EdmEntityContainer("ns", "container");
model.AddElement(container);
AddEdmElement(model);
AddEdmFunction(model);
AddTableValueFunction(model);
BuildRelation(model);
return model;
});
}
示例4: EdmSingletonAnnotationTests
public void EdmSingletonAnnotationTests()
{
EdmModel model = new EdmModel();
EdmStructuralProperty customerProperty = new EdmStructuralProperty(customerType, "Name", EdmCoreModel.Instance.GetString(false));
customerType.AddProperty(customerProperty);
model.AddElement(this.customerType);
EdmSingleton vipCustomer = new EdmSingleton(this.entityContainer, "VIP", this.customerType);
EdmTerm term = new EdmTerm(myNamespace, "SingletonAnnotation", EdmPrimitiveTypeKind.String);
var annotation = new EdmAnnotation(vipCustomer, term, new EdmStringConstant("Singleton Annotation"));
model.AddVocabularyAnnotation(annotation);
var singletonAnnotation = vipCustomer.VocabularyAnnotations(model).Single();
Assert.Equal(vipCustomer, singletonAnnotation.Target);
Assert.Equal("SingletonAnnotation", singletonAnnotation.Term.Name);
singletonAnnotation = model.FindDeclaredVocabularyAnnotations(vipCustomer).Single();
Assert.Equal(vipCustomer, singletonAnnotation.Target);
Assert.Equal("SingletonAnnotation", singletonAnnotation.Term.Name);
EdmTerm propertyTerm = new EdmTerm(myNamespace, "SingletonPropertyAnnotation", EdmPrimitiveTypeKind.String);
var propertyAnnotation = new EdmAnnotation(customerProperty, propertyTerm, new EdmStringConstant("Singleton Property Annotation"));
model.AddVocabularyAnnotation(propertyAnnotation);
var singletonPropertyAnnotation = customerProperty.VocabularyAnnotations(model).Single();
Assert.Equal(customerProperty, singletonPropertyAnnotation.Target);
Assert.Equal("SingletonPropertyAnnotation", singletonPropertyAnnotation.Term.Name);
}
示例5: GetModelID_Returns_DifferentIDForDifferentModels
public void GetModelID_Returns_DifferentIDForDifferentModels()
{
EdmModel model1 = new EdmModel();
EdmModel model2 = new EdmModel();
Assert.NotEqual(ModelContainer.GetModelID(model1), ModelContainer.GetModelID(model2));
}
示例6: 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);
}
示例7: WriteComplexParameterWithoutTypeInformationErrorTest
public void WriteComplexParameterWithoutTypeInformationErrorTest()
{
EdmModel edmModel = new EdmModel();
var container = new EdmEntityContainer("DefaultNamespace", "DefaultContainer");
edmModel.AddElement(container);
var testDescriptors = new PayloadWriterTestDescriptor<ODataParameters>[]
{
new PayloadWriterTestDescriptor<ODataParameters>(
this.Settings,
new ODataParameters()
{
new KeyValuePair<string, object>("p1", new ODataComplexValue())
},
tc => new WriterTestExpectedResults(this.ExpectedResultSettings)
{
ExpectedException2 = ODataExpectedExceptions.ODataException("ODataJsonLightPropertyAndValueSerializer_NoExpectedTypeOrTypeNameSpecifiedForComplexValueRequest")
})
{
DebugDescription = "Complex value without expected type or type name.",
Model = edmModel
},
};
this.CombinatorialEngineProvider.RunCombinations(
testDescriptors,
this.WriterTestConfigurationProvider.JsonLightFormatConfigurations.Where(tc => tc.IsRequest),
(testDescriptor, testConfiguration) =>
{
TestWriterUtils.WriteAndVerifyODataParameterPayload(testDescriptor, testConfiguration, this.Assert, this.Logger);
});
}
示例8: CreateEntryWithKeyAsSegmentConvention
private static ODataEntry CreateEntryWithKeyAsSegmentConvention(bool addAnnotation, bool? useKeyAsSegment)
{
var model = new EdmModel();
var container = new EdmEntityContainer("Fake", "Container");
model.AddElement(container);
if (addAnnotation)
{
model.AddVocabularyAnnotation(new EdmAnnotation(container, UrlConventionsConstants.ConventionTerm, UrlConventionsConstants.KeyAsSegmentAnnotationValue));
}
EdmEntityType entityType = new EdmEntityType("Fake", "FakeType");
entityType.AddKeys(entityType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
model.AddElement(entityType);
var entitySet = new EdmEntitySet(container, "FakeSet", entityType);
container.AddElement(entitySet);
var metadataContext = new ODataMetadataContext(
true,
ODataReaderBehavior.DefaultBehavior.OperationsBoundToEntityTypeMustBeContainerQualified,
new EdmTypeReaderResolver(model, ODataReaderBehavior.DefaultBehavior),
model,
new Uri("http://temp.org/$metadata"),
null /*requestUri*/);
var thing = new ODataEntry {Properties = new[] {new ODataProperty {Name = "Id", Value = 1}}};
thing.SetAnnotation(new ODataTypeAnnotation(entitySet, entityType));
thing.MetadataBuilder = metadataContext.GetEntityMetadataBuilderForReader(new TestJsonLightReaderEntryState { Entry = thing, SelectedProperties = new SelectedPropertiesNode("*")}, useKeyAsSegment);
return thing;
}
示例9: AdvancedMapODataServiceRoute_ConfiguresARoute_WithAnODataRouteAndVersionConstraints
public void AdvancedMapODataServiceRoute_ConfiguresARoute_WithAnODataRouteAndVersionConstraints()
{
// Arrange
HttpRouteCollection routes = new HttpRouteCollection();
HttpConfiguration config = new HttpConfiguration(routes);
IEdmModel model = new EdmModel();
string routeName = "name";
string routePrefix = "prefix";
var pathHandler = new DefaultODataPathHandler();
var conventions = new List<IODataRoutingConvention>();
// Act
config.MapODataServiceRoute(routeName, routePrefix, model, pathHandler, conventions);
// Assert
IHttpRoute odataRoute = routes[routeName];
Assert.Single(routes);
Assert.Equal(routePrefix + "/{*odataPath}", odataRoute.RouteTemplate);
Assert.Equal(2, odataRoute.Constraints.Count);
var odataPathConstraint = Assert.Single(odataRoute.Constraints.Values.OfType<ODataPathRouteConstraint>());
Assert.Same(model, odataPathConstraint.EdmModel);
Assert.IsType<DefaultODataPathHandler>(odataPathConstraint.PathHandler);
Assert.NotNull(odataPathConstraint.RoutingConventions);
var odataVersionConstraint = Assert.Single(odataRoute.Constraints.Values.OfType<ODataVersionConstraint>());
Assert.NotNull(odataVersionConstraint.Version);
Assert.Equal(ODataVersion.V4, odataVersionConstraint.Version);
}
示例10: CraftModel
public CraftModel()
{
model = new EdmModel();
var address = new EdmComplexType("NS", "Address");
model.AddElement(address);
var mail = new EdmEntityType("NS", "Mail");
var mailId = mail.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32);
mail.AddKeys(mailId);
model.AddElement(mail);
var person = new EdmEntityType("NS", "Person");
model.AddElement(person);
var personId = person.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32);
person.AddKeys(personId);
person.AddStructuralProperty("Addr", new EdmComplexTypeReference(address, /*Nullable*/false));
MailBox = person.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
{
ContainsTarget = true,
Name = "Mails",
TargetMultiplicity = EdmMultiplicity.Many,
Target = mail,
});
var container = new EdmEntityContainer("NS", "DefaultContainer");
model.AddElement(container);
MyLogin = container.AddSingleton("MyLogin", person);
}
示例11: ODataFeedAndEntryTypeContextTests
static ODataFeedAndEntryTypeContextTests()
{
Model = new EdmModel();
EntitySetElementType = new EdmEntityType("ns", "Customer");
ExpectedEntityType = new EdmEntityType("ns", "VipCustomer", EntitySetElementType);
ActualEntityType = new EdmEntityType("ns", "DerivedVipCustomer", ExpectedEntityType);
EdmEntityContainer defaultContainer = new EdmEntityContainer("ns", "DefaultContainer");
Model.AddElement(defaultContainer);
Model.AddVocabularyAnnotation(new EdmAnnotation(defaultContainer, UrlConventionsConstants.ConventionTerm, UrlConventionsConstants.KeyAsSegmentAnnotationValue));
EntitySet = new EdmEntitySet(defaultContainer, "Customers", EntitySetElementType);
Model.AddElement(EntitySetElementType);
Model.AddElement(ExpectedEntityType);
Model.AddElement(ActualEntityType);
defaultContainer.AddElement(EntitySet);
SerializationInfo = new ODataFeedAndEntrySerializationInfo { NavigationSourceName = "MyCustomers", NavigationSourceEntityTypeName = "ns.MyCustomer", ExpectedTypeName = "ns.MyVipCustomer" };
SerializationInfoWithEdmUnknowEntitySet = new ODataFeedAndEntrySerializationInfo() { NavigationSourceName = null, NavigationSourceEntityTypeName = "ns.MyCustomer", ExpectedTypeName = "ns.MyVipCustomer", NavigationSourceKind = EdmNavigationSourceKind.UnknownEntitySet };
TypeContextWithoutModel = ODataFeedAndEntryTypeContext.Create(SerializationInfo, navigationSource: null, navigationSourceEntityType: null, expectedEntityType: null, model: Model, throwIfMissingTypeInfo: true);
TypeContextWithModel = ODataFeedAndEntryTypeContext.Create(/*serializationInfo*/null, EntitySet, EntitySetElementType, ExpectedEntityType, Model, throwIfMissingTypeInfo: true);
TypeContextWithEdmUnknowEntitySet = ODataFeedAndEntryTypeContext.Create(SerializationInfoWithEdmUnknowEntitySet, navigationSource: null, navigationSourceEntityType: null, expectedEntityType: null, model: Model, throwIfMissingTypeInfo: true);
BaseTypeContextThatThrows = ODataFeedAndEntryTypeContext.Create(serializationInfo: null, navigationSource: null, navigationSourceEntityType: null, expectedEntityType: null, model: Model, throwIfMissingTypeInfo: true);
BaseTypeContextThatWillNotThrow = ODataFeedAndEntryTypeContext.Create(serializationInfo: null, navigationSource: null, navigationSourceEntityType: null, expectedEntityType: null, model: Model, throwIfMissingTypeInfo: false);
}
示例12: MultipleSchemasWithDifferentNamespacesEdm
public static IEdmModel MultipleSchemasWithDifferentNamespacesEdm()
{
var namespaces = new string[]
{
"FindMethodsTestModelBuilder.MultipleSchemasWithDifferentNamespaces.first",
"FindMethodsTestModelBuilder.MultipleSchemasWithDifferentNamespaces.second"
};
var model = new EdmModel();
foreach (var namespaceName in namespaces)
{
var entityType1 = new EdmEntityType(namespaceName, "validEntityType1");
entityType1.AddKeys(entityType1.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
var entityType2 = new EdmEntityType(namespaceName, "VALIDeNTITYtYPE2");
entityType2.AddKeys(entityType2.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
var entityType3 = new EdmEntityType(namespaceName, "VALIDeNTITYtYPE3");
entityType3.AddKeys(entityType3.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
entityType1.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo {Name = "Mumble", Target = entityType2, TargetMultiplicity = EdmMultiplicity.Many});
var complexType = new EdmComplexType(namespaceName, "ValidNameComplexType1");
complexType.AddStructuralProperty("aPropertyOne", new EdmComplexTypeReference(complexType, false));
model.AddElements(new IEdmSchemaElement[] { entityType1, entityType2, entityType3, complexType });
var function1 = new EdmFunction(namespaceName, "ValidFunction1", EdmCoreModel.Instance.GetSingle(false));
var function2 = new EdmFunction(namespaceName, "ValidFunction1", EdmCoreModel.Instance.GetSingle(false));
function2.AddParameter("param1", new EdmEntityTypeReference(entityType1, false));
var function3 = new EdmFunction(namespaceName, "ValidFunction1", EdmCoreModel.Instance.GetSingle(false));
function3.AddParameter("param1", EdmCoreModel.Instance.GetSingle(false));
model.AddElements(new IEdmSchemaElement[] {function1, function2, function3});
}
return model;
}
示例13: AmbiguousValueTermTest
public void AmbiguousValueTermTest()
{
EdmModel model = new EdmModel();
IEdmValueTerm term1 = new EdmTerm("Foo", "Bar", EdmPrimitiveTypeKind.Byte);
IEdmValueTerm term2 = new EdmTerm("Foo", "Bar", EdmPrimitiveTypeKind.Decimal);
IEdmValueTerm term3 = new EdmTerm("Foo", "Bar", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Double, false));
Assert.AreEqual(EdmTermKind.Value, term1.TermKind, "EdmTermKind is correct.");
model.AddElement(term1);
Assert.AreEqual(term1, model.FindValueTerm("Foo.Bar"), "Correct item.");
model.AddElement(term2);
model.AddElement(term3);
IEdmValueTerm ambiguous = model.FindValueTerm("Foo.Bar");
Assert.IsTrue(ambiguous.IsBad(), "Ambiguous binding is bad");
Assert.AreEqual(EdmSchemaElementKind.ValueTerm, ambiguous.SchemaElementKind, "Correct schema element kind.");
Assert.AreEqual("Foo", ambiguous.Namespace, "Correct Namespace");
Assert.AreEqual("Bar", ambiguous.Name, "Correct Name");
Assert.AreEqual(EdmTermKind.Value, ambiguous.TermKind, "Correct term kind.");
Assert.IsTrue(ambiguous.Type.IsBad(), "Type is bad.");
}
示例14: BatchReaderPayloadTest
public void BatchReaderPayloadTest()
{
var model = new EdmModel();
IEnumerable<PayloadTestDescriptor> batchRequestDescriptors =
TestBatches.CreateBatchRequestTestDescriptors(this.RequestManager, model, /*withTypeNames*/ true);
IEnumerable<PayloadReaderTestDescriptor> requestTestDescriptors =
batchRequestDescriptors.Select(bd => new PayloadReaderTestDescriptor(this.PayloadReaderSettings)
{
PayloadDescriptor = bd,
SkipTestConfiguration = tc => !tc.IsRequest || (tc.Format != ODataFormat.Json && tc.Format != ODataFormat.Atom)
});
IEnumerable<PayloadTestDescriptor> batchResponseDescriptors =
TestBatches.CreateBatchResponseTestDescriptors(this.RequestManager, model, /*withTypeNames*/ true);
IEnumerable<PayloadReaderTestDescriptor> responseTestDescriptors =
batchResponseDescriptors.Select(bd => new PayloadReaderTestDescriptor(this.PayloadReaderSettings)
{
PayloadDescriptor = bd,
SkipTestConfiguration = tc => tc.IsRequest || (tc.Format != ODataFormat.Json && tc.Format != ODataFormat.Atom)
});
IEnumerable<PayloadReaderTestDescriptor> testDescriptors = requestTestDescriptors.Concat(responseTestDescriptors);
this.CombinatorialEngineProvider.RunCombinations(
testDescriptors,
this.ReaderTestConfigurationProvider.DefaultFormatConfigurations,
(testDescriptor, testConfiguration) =>
{
testDescriptor.RunTest(testConfiguration);
});
}
示例15: GetEdmModel
public static IEdmModel GetEdmModel()
{
EdmModel model = new EdmModel();
// Create and add product entity type.
EdmEntityType product = new EdmEntityType("NS", "Product");
product.AddKeys(product.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
product.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
product.AddStructuralProperty("Price", EdmPrimitiveTypeKind.Double);
model.AddElement(product);
// Create and add category entity type.
EdmEntityType category = new EdmEntityType("NS", "Category");
category.AddKeys(category.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
category.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
model.AddElement(category);
// Set navigation from product to category.
EdmNavigationPropertyInfo propertyInfo = new EdmNavigationPropertyInfo();
propertyInfo.Name = "Category";
propertyInfo.TargetMultiplicity = EdmMultiplicity.One;
propertyInfo.Target = category;
EdmNavigationProperty productCategory = product.AddUnidirectionalNavigation(propertyInfo);
// Create and add entity container.
EdmEntityContainer container = new EdmEntityContainer("NS", "DefaultContainer");
model.AddElement(container);
// Create and add entity set for product and category.
EdmEntitySet products = container.AddEntitySet("Products", product);
EdmEntitySet categories = container.AddEntitySet("Categories", category);
products.AddNavigationTarget(productCategory, categories);
return model;
}