本文整理汇总了C#中Microsoft.OData.Edm.Library.EdmEntityContainer类的典型用法代码示例。如果您正苦于以下问题:C# EdmEntityContainer类的具体用法?C# EdmEntityContainer怎么用?C# EdmEntityContainer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EdmEntityContainer类属于Microsoft.OData.Edm.Library命名空间,在下文中一共展示了EdmEntityContainer类的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, IEdmType> edmTypeMap = model.AddTypes(builder.StructuralTypes, builder.EnumTypes);
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));
// set the data service version annotations.
model.SetDataServiceVersion(builder.DataServiceVersion);
model.SetMaxDataServiceVersion(builder.MaxDataServiceVersion);
return model;
}
示例2: 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;
}
示例3: AddEntitySets
private static Dictionary<string, EdmEntitySet> AddEntitySets(this EdmModel model, ODataModelBuilder builder,
EdmEntityContainer container, Dictionary<Type, IEdmType> edmTypeMap)
{
IEnumerable<EntitySetConfiguration> configurations = builder.EntitySets;
// build the entitysets and their annotations
IEnumerable<Tuple<EdmEntitySet, EntitySetConfiguration>> entitySets = AddEntitySets(configurations, container, edmTypeMap);
var entitySetAndAnnotations = entitySets.Select(e => new
{
EntitySet = e.Item1,
Configuration = e.Item2,
Annotations = new
{
LinkBuilder = new EntitySetLinkBuilderAnnotation(e.Item2),
Url = new EntitySetUrlAnnotation { Url = e.Item2.GetUrl() }
}
}).ToArray();
// index the entitySets by name
Dictionary<string, EdmEntitySet> edmEntitySetMap = entitySetAndAnnotations.ToDictionary(e => e.EntitySet.Name, e => e.EntitySet);
// apply the annotations
foreach (var iter in entitySetAndAnnotations)
{
EdmEntitySet entitySet = iter.EntitySet;
model.SetAnnotationValue<EntitySetUrlAnnotation>(entitySet, iter.Annotations.Url);
model.SetEntitySetLinkBuilder(entitySet, iter.Annotations.LinkBuilder);
AddNavigationBindings(iter.Configuration, iter.EntitySet, iter.Annotations.LinkBuilder, builder, edmTypeMap, edmEntitySetMap);
}
return edmEntitySetMap;
}
示例4: 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;
}
示例5: 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);
}
示例6: 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);
});
}
示例7: 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;
}
示例8: InstanceAnnotationsReaderIntegrationTests
static InstanceAnnotationsReaderIntegrationTests()
{
EdmModel modelTmp = new EdmModel();
EntityType = new EdmEntityType("TestNamespace", "TestEntityType");
modelTmp.AddElement(EntityType);
var keyProperty = new EdmStructuralProperty(EntityType, "ID", EdmCoreModel.Instance.GetInt32(false));
EntityType.AddKeys(new IEdmStructuralProperty[] { keyProperty });
EntityType.AddProperty(keyProperty);
var resourceNavigationProperty = EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "ResourceNavigationProperty", Target = EntityType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne });
var resourceSetNavigationProperty = EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "ResourceSetNavigationProperty", Target = EntityType, TargetMultiplicity = EdmMultiplicity.Many });
var defaultContainer = new EdmEntityContainer("TestNamespace", "DefaultContainer_sub");
modelTmp.AddElement(defaultContainer);
EntitySet = new EdmEntitySet(defaultContainer, "TestEntitySet", EntityType);
EntitySet.AddNavigationTarget(resourceNavigationProperty, EntitySet);
EntitySet.AddNavigationTarget(resourceSetNavigationProperty, EntitySet);
defaultContainer.AddElement(EntitySet);
Singleton = new EdmSingleton(defaultContainer, "TestSingleton", EntityType);
Singleton.AddNavigationTarget(resourceNavigationProperty, EntitySet);
Singleton.AddNavigationTarget(resourceSetNavigationProperty, EntitySet);
defaultContainer.AddElement(Singleton);
ComplexType = new EdmComplexType("TestNamespace", "TestComplexType");
ComplexType.AddProperty(new EdmStructuralProperty(ComplexType, "StringProperty", EdmCoreModel.Instance.GetString(false)));
modelTmp.AddElement(ComplexType);
Model = TestUtils.WrapReferencedModelsToMainModel("TestNamespace", "DefaultContainer", modelTmp);
}
示例9: ODataSingletonDeserializerTest
public ODataSingletonDeserializerTest()
{
EdmModel model = new EdmModel();
var employeeType = new EdmEntityType("NS", "Employee");
employeeType.AddStructuralProperty("EmployeeId", EdmPrimitiveTypeKind.Int32);
employeeType.AddStructuralProperty("EmployeeName", EdmPrimitiveTypeKind.String);
model.AddElement(employeeType);
EdmEntityContainer defaultContainer = new EdmEntityContainer("NS", "Default");
model.AddElement(defaultContainer);
_singleton = new EdmSingleton(defaultContainer, "CEO", employeeType);
defaultContainer.AddElement(_singleton);
model.SetAnnotationValue<ClrTypeAnnotation>(employeeType, new ClrTypeAnnotation(typeof(EmployeeModel)));
_edmModel = model;
_edmContainer = defaultContainer;
_readContext = new ODataDeserializerContext
{
Path = new ODataPath(new SingletonPathSegment(_singleton)),
Model = _edmModel,
ResourceType = typeof(EmployeeModel)
};
_deserializerProvider = new DefaultODataDeserializerProvider();
}
示例10: EdmSingletonTests
public EdmSingletonTests()
{
this.entityContainer = new EdmEntityContainer(myNamespace, "Container");
this.customerType = new EdmEntityType(myNamespace, "Customer");
this.orderType = new EdmEntityType(myNamespace, "Order");
this.productType = new EdmEntityType(myNamespace, "Product");
}
示例11: 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;
});
}
示例12: WriterTypeNameEndToEndTests
public WriterTypeNameEndToEndTests()
{
var model = new EdmModel();
var type = new EdmEntityType("TestModel", "TestEntity", /* baseType */ null, /* isAbstract */ false, /* isOpen */ true);
var keyProperty = type.AddStructuralProperty("DeclaredInt16", EdmPrimitiveTypeKind.Int16);
type.AddKeys(new[] { keyProperty });
// Note: DerivedPrimitive is declared as a Geography, but its value below will be set to GeographyPoint, which is derived from Geography.
type.AddStructuralProperty("DerivedPrimitive", EdmPrimitiveTypeKind.Geography);
var container = new EdmEntityContainer("TestModel", "Container");
var set = container.AddEntitySet("Set", type);
model.AddElement(type);
model.AddElement(container);
var writerStream = new MemoryStream();
this.settings = new ODataMessageWriterSettings();
this.settings.SetServiceDocumentUri(ServiceDocumentUri);
// Make the message writer and entry writer lazy so that individual tests can tweak the settings before the message writer is created.
this.messageWriter = new Lazy<ODataMessageWriter>(() =>
new ODataMessageWriter(
(IODataResponseMessage)new InMemoryMessage { Stream = writerStream },
this.settings,
model));
var entryWriter = new Lazy<ODataWriter>(() => this.messageWriter.Value.CreateODataEntryWriter(set, type));
var valueWithAnnotation = new ODataPrimitiveValue(45);
valueWithAnnotation.SetAnnotation(new SerializationTypeNameAnnotation { TypeName = "TypeNameFromSTNA" });
var propertiesToWrite = new List<ODataProperty>
{
new ODataProperty
{
Name = "DeclaredInt16", Value = (Int16)42
},
new ODataProperty
{
Name = "UndeclaredDecimal", Value = (Decimal)4.5
},
new ODataProperty
{
// Note: value is more derived than the declared type.
Name = "DerivedPrimitive", Value = Microsoft.Spatial.GeographyPoint.Create(42, 45)
},
new ODataProperty()
{
Name = "PropertyWithSTNA", Value = valueWithAnnotation
}
};
this.writerOutput = new Lazy<string>(() =>
{
entryWriter.Value.WriteStart(new ODataEntry { Properties = propertiesToWrite });
entryWriter.Value.WriteEnd();
entryWriter.Value.Flush();
writerStream.Seek(0, SeekOrigin.Begin);
return new StreamReader(writerStream).ReadToEnd();
});
}
示例13: GetEdmModel
private IEdmModel GetEdmModel()
{
EdmModel model = new EdmModel();
EdmEntityContainer container = new EdmEntityContainer("NS", "Name");
model.AddElement(container);
IEdmTypeReference returnType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false);
IEdmTypeReference parameterType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false);
container.AddFunctionImport(new EdmFunction("NS", "FunctionWithoutParams", returnType));
var functionWithOneParam = new EdmFunction("NS", "FunctionWithOneParam", returnType);
functionWithOneParam.AddParameter("Parameter", parameterType);
container.AddFunctionImport(functionWithOneParam);
var functionWithMultipleParams = new EdmFunction("NS", "FunctionWithMultipleParams", returnType);
functionWithMultipleParams.AddParameter("Parameter1", parameterType);
functionWithMultipleParams.AddParameter("Parameter2", parameterType);
functionWithMultipleParams.AddParameter("Parameter3", parameterType);
container.AddFunctionImport(functionWithMultipleParams);
container.AddFunctionImport(new EdmFunction("NS", "FunctionWithOverloads", returnType));
var functionWithOverloads2 = new EdmFunction("NS", "FunctionWithOverloads", returnType);
functionWithOverloads2.AddParameter("Parameter", parameterType);
container.AddFunctionImport(functionWithOverloads2);
var functionWithOverloads3 = new EdmFunction("NS", "FunctionWithOverloads", returnType);
functionWithOverloads3.AddParameter("Parameter1", parameterType);
functionWithOverloads3.AddParameter("Parameter2", parameterType);
functionWithOverloads3.AddParameter("Parameter3", parameterType);
container.AddFunctionImport(functionWithOverloads3);
return model;
}
示例14: Ctor_InitializeParameterMappingsProperty_UnboundFunction
public void Ctor_InitializeParameterMappingsProperty_UnboundFunction()
{
// Arrange
IEdmModel model = new Mock<IEdmModel>().Object;
IEdmEntityType returnType = new Mock<IEdmEntityType>().Object;
EdmEntityContainer container = new EdmEntityContainer("NS", "Container");
EdmFunctionImport function = new EdmFunctionImport(
container,
"Function",
new EdmFunction(
"NS",
"Function",
new EdmEntityTypeReference(returnType, isNullable: false)));
Dictionary<string, string> parameterMappings = new Dictionary<string, string>
{
{ "Parameter1", "{param1}" },
{ "Parameter2", "{param2}" }
};
// Act
var template = new UnboundFunctionPathSegmentTemplate(
new UnboundFunctionPathSegment(function, model, parameterMappings));
// Assert
Assert.Equal(2, template.ParameterMappings.Count);
}
示例15: GetEdmModel
public static IEdmModel GetEdmModel()
{
if (_edmModel != null)
{
return _edmModel;
}
EdmModel model = new EdmModel();
// entity type 'Customer' with single alternate keys
EdmEntityType customer = new EdmEntityType("NS", "Customer");
customer.AddKeys(customer.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32));
customer.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
var ssn = customer.AddStructuralProperty("SSN", EdmPrimitiveTypeKind.String);
model.AddAlternateKeyAnnotation(customer, new Dictionary<string, IEdmProperty>
{
{"SSN", ssn}
});
model.AddElement(customer);
// entity type 'Order' with multiple alternate keys
EdmEntityType order = new EdmEntityType("NS", "Order");
order.AddKeys(order.AddStructuralProperty("OrderId", EdmPrimitiveTypeKind.Int32));
var orderName = order.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
var orderToken = order.AddStructuralProperty("Token", EdmPrimitiveTypeKind.Guid);
order.AddStructuralProperty("Amount", EdmPrimitiveTypeKind.Int32);
model.AddAlternateKeyAnnotation(order, new Dictionary<string, IEdmProperty>
{
{"Name", orderName}
});
model.AddAlternateKeyAnnotation(order, new Dictionary<string, IEdmProperty>
{
{"Token", orderToken}
});
model.AddElement(order);
// entity type 'Person' with composed alternate keys
EdmEntityType person = new EdmEntityType("NS", "Person");
person.AddKeys(person.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32));
var country = person.AddStructuralProperty("Country", EdmPrimitiveTypeKind.String);
var passport = person.AddStructuralProperty("Passport", EdmPrimitiveTypeKind.String);
model.AddAlternateKeyAnnotation(person, new Dictionary<string, IEdmProperty>
{
{"Country", country},
{"Passport", passport}
});
model.AddElement(person);
// entity sets
EdmEntityContainer container = new EdmEntityContainer("NS", "Default");
model.AddElement(container);
container.AddEntitySet("Customers", customer);
container.AddEntitySet("Orders", order);
container.AddEntitySet("People", person);
return _edmModel = model;
}