本文整理汇总了C#中Microsoft.Data.Edm.Library.EdmModel类的典型用法代码示例。如果您正苦于以下问题:C# EdmModel类的具体用法?C# EdmModel怎么用?C# EdmModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EdmModel类属于Microsoft.Data.Edm.Library命名空间,在下文中一共展示了EdmModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildEdmModel
public static IEdmModel BuildEdmModel(ODataModelBuilder builder)
{
if (builder == null)
{
throw Error.ArgumentNull("builder");
}
EdmModel model = new EdmModel();
EdmEntityContainer container = new EdmEntityContainer(builder.Namespace, builder.ContainerName);
// add types and sets, building an index on the way.
Dictionary<Type, IEdmStructuredType> edmTypeMap = model.AddTypes(builder.StructuralTypes);
Dictionary<string, EdmEntitySet> edmEntitySetMap = model.AddEntitySets(builder, container, edmTypeMap);
// add procedures
model.AddProcedures(builder.Procedures, container, edmTypeMap, edmEntitySetMap);
// finish up
model.AddElement(container);
// build the map from IEdmEntityType to IEdmFunctionImport
model.SetAnnotationValue<BindableProcedureFinder>(model, new BindableProcedureFinder(model));
return model;
}
示例2: CreateCustomerProductsModel
private static EdmModel CreateCustomerProductsModel()
{
var model = new EdmModel();
var container = new EdmEntityContainer("defaultNamespace", "DefaultContainer");
model.AddElement(container);
var productType = new EdmEntityType("defaultNamespace", "Product");
model.AddElement(productType);
var customerType = new EdmEntityType("defaultNamespace", "Customer");
customerType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Products", Target = productType, TargetMultiplicity = EdmMultiplicity.Many });
productType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Customers", Target = customerType, TargetMultiplicity = EdmMultiplicity.Many });
model.AddElement(customerType);
var productSet = new EdmEntitySet(
container,
"Products",
productType);
container.AddElement(productSet);
var customerSet = new EdmEntitySet(
container,
"Customers",
customerType);
var productsNavProp = customerType.NavigationProperties().Single(np => np.Name == "Products");
customerSet.AddNavigationTarget(productsNavProp, productSet);
container.AddElement(customerSet);
return model;
}
示例3: AdvancedMapODataServiceRoute_ConfiguresARoute_WithAnODataRouteConstraintAndVersionConstraints
public void AdvancedMapODataServiceRoute_ConfiguresARoute_WithAnODataRouteConstraintAndVersionConstraints()
{
// Arrange
HttpRouteCollection routes = new HttpRouteCollection();
IEdmModel model = new EdmModel();
string routeName = "name";
string routePrefix = "prefix";
var pathHandler = new DefaultODataPathHandler();
var conventions = new List<IODataRoutingConvention>();
// Act
routes.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.Equal(ODataVersion.V1, odataVersionConstraint.MinVersion);
Assert.Equal(ODataVersion.V3, odataVersionConstraint.MaxVersion);
}
示例4: ConvertToEdmEntityType
private EdmEntityType ConvertToEdmEntityType(JSchema schema, EdmModel model, string name)
{
var type = new EdmEntityType("namespace", name);
foreach (var property in schema.Properties)
{
if (property.Value.Type == null)
throw new Exception("Type specyfication missing.");
var structuralType = MapPropertyToStructuralType(property, schema, model);
if (structuralType != null)
{
type.AddStructuralProperty(property.Key, structuralType);
}
else
{
type.AddStructuralProperty(property.Key, ToEdmPrimitiveType(property.Value.Type.Value));
}
}
model.AddElement(type);
return type;
}
示例5: GetModelID_AndThen_GetModel_ReturnsOriginalModel
public void GetModelID_AndThen_GetModel_ReturnsOriginalModel()
{
EdmModel model = new EdmModel();
string modelID = ModelContainer.GetModelID(model);
Assert.Same(model, ModelContainer.GetModel(modelID));
}
示例6: GetModelID_Returns_DifferentIDForDifferentModels
public void GetModelID_Returns_DifferentIDForDifferentModels()
{
EdmModel model1 = new EdmModel();
EdmModel model2 = new EdmModel();
Assert.NotEqual(ModelContainer.GetModelID(model1), ModelContainer.GetModelID(model2));
}
示例7: GetActionLinkBuilder_ReturnsDefaultActionLinkBuilder_IfNotSet
public void GetActionLinkBuilder_ReturnsDefaultActionLinkBuilder_IfNotSet()
{
// Arrange
IEdmModel model = new EdmModel();
IEdmEntityContainer container = new EdmEntityContainer("NS", "Container");
IEdmFunctionImport action = new EdmFunctionImport(container, "Action", returnType: null);
Assert.NotNull(model.GetActionLinkBuilder(action));
}
示例8: GetEntitySetLinkBuilder_ReturnsDefaultEntitySetBuilder_IfNotSet
public void GetEntitySetLinkBuilder_ReturnsDefaultEntitySetBuilder_IfNotSet()
{
IEdmModel model = new EdmModel();
EdmEntityContainer container = new EdmEntityContainer("NS", "Container");
EdmEntityType entityType = new EdmEntityType("NS", "Entity");
IEdmEntitySet entitySet = new EdmEntitySet(container, "EntitySet", entityType);
Assert.NotNull(model.GetEntitySetLinkBuilder(entitySet));
}
示例9: PathHandlerGetter_ReturnsDefaultPathHandlerByDefault
public void PathHandlerGetter_ReturnsDefaultPathHandlerByDefault()
{
HttpRequestMessage request = new HttpRequestMessage();
IEdmModel model = new EdmModel();
request.ODataProperties().Model = model;
var pathHandler = request.ODataProperties().PathHandler;
Assert.NotNull(pathHandler);
Assert.IsType<DefaultODataPathHandler>(pathHandler);
}
示例10: GetODataPathHandlerReturnsDefaultPathHandlerByDefault
public void GetODataPathHandlerReturnsDefaultPathHandlerByDefault()
{
HttpRequestMessage request = new HttpRequestMessage();
IEdmModel model = new EdmModel();
request.SetEdmModel(model);
var pathHandler = request.GetODataPathHandler();
Assert.NotNull(pathHandler);
Assert.IsType<DefaultODataPathHandler>(pathHandler);
}
示例11: SimpleCustomerOrderModel
public static IEdmModel SimpleCustomerOrderModel()
{
var model = new EdmModel();
var customerType = new EdmEntityType("Default", "Customer");
customerType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32);
customerType.AddStructuralProperty("FirstName", EdmPrimitiveTypeKind.String);
customerType.AddStructuralProperty("LastName", EdmPrimitiveTypeKind.String);
IEdmTypeReference primitiveTypeReference = EdmCoreModel.Instance
.GetPrimitive(EdmPrimitiveTypeKind.String, isNullable: true);
customerType.AddStructuralProperty("City", primitiveTypeReference, defaultValue: null,
concurrencyMode: EdmConcurrencyMode.Fixed);
model.AddElement(customerType);
var orderType = new EdmEntityType("Default", "Order");
orderType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32);
orderType.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
orderType.AddStructuralProperty("Shipment", EdmPrimitiveTypeKind.String);
model.AddElement(orderType);
var addressType = new EdmComplexType("Default", "Address");
addressType.AddStructuralProperty("Street", EdmPrimitiveTypeKind.String);
addressType.AddStructuralProperty("City", EdmPrimitiveTypeKind.String);
addressType.AddStructuralProperty("State", EdmPrimitiveTypeKind.String);
addressType.AddStructuralProperty("Country", EdmPrimitiveTypeKind.String);
addressType.AddStructuralProperty("ZipCode", EdmPrimitiveTypeKind.String);
model.AddElement(addressType);
// Add navigations
customerType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
{
Name = "Orders",
Target = orderType,
TargetMultiplicity = EdmMultiplicity.Many
});
orderType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
{
Name = "Customer",
Target = customerType,
TargetMultiplicity = EdmMultiplicity.One
});
var container = new EdmEntityContainer("Default", "Container");
var customerSet = container.AddEntitySet("Customers", customerType);
var orderSet = container.AddEntitySet("Orders", orderType);
customerSet.AddNavigationTarget(customerType.NavigationProperties().Single(np => np.Name == "Orders"), orderSet);
orderSet.AddNavigationTarget(orderType.NavigationProperties().Single(np => np.Name == "Customer"), customerSet);
EntitySetLinkBuilderAnnotation linkAnnotation = new MockEntitySetLinkBuilderAnnotation();
model.SetEntitySetLinkBuilder(customerSet, linkAnnotation);
model.SetEntitySetLinkBuilder(orderSet, linkAnnotation);
model.AddElement(container);
return model;
}
示例12: GetMetadata_Returns_EdmModelFromRequest
public void GetMetadata_Returns_EdmModelFromRequest()
{
IEdmModel model = new EdmModel();
ODataMetadataController controller = new ODataMetadataController();
controller.Request = new HttpRequestMessage();
controller.Request.ODataProperties().Model = model;
IEdmModel responseModel = controller.GetMetadata();
Assert.Equal(model, responseModel);
}
示例13: MapArray
private IEdmTypeReference MapArray(KeyValuePair<string, JSchema> property, JSchema parent, EdmModel model)
{
var entityPrimitiveType = ToEdmPrimitiveType(property.Value.Items.Single().Type.Value);
var entityType = EdmCoreModel.Instance.GetPrimitiveType(entityPrimitiveType);
var collectionType = new EdmCollectionType(new EdmPrimitiveTypeReference(entityType, false));
bool isNullable = !parent.Required.Contains(property.Key);
return new EdmCollectionTypeReference(collectionType, isNullable);
}
示例14: ToEdmModel
public IEdmModel ToEdmModel(JSchema schema)
{
var model = new EdmModel();
var container = new EdmEntityContainer("namespace", "containerName");
var rootType = ConvertToEdmEntityType(schema, model, "root");
container.AddEntitySet("root", rootType);
model.AddElement(container);
return model;
}
示例15: ModelGetter_Returns_ModelSetter
public void ModelGetter_Returns_ModelSetter()
{
// Arrange
HttpRequestMessage request = new HttpRequestMessage();
IEdmModel model = new EdmModel();
// Act
request.ODataProperties().Model = model;
IEdmModel newModel = request.ODataProperties().Model;
// Assert
Assert.Same(model, newModel);
}