本文整理汇总了C#中Microsoft.OData.Edm.Library.EdmModel.EnsureEntityContainer方法的典型用法代码示例。如果您正苦于以下问题:C# EdmModel.EnsureEntityContainer方法的具体用法?C# EdmModel.EnsureEntityContainer怎么用?C# EdmModel.EnsureEntityContainer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.OData.Edm.Library.EdmModel
的用法示例。
在下文中一共展示了EdmModel.EnsureEntityContainer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildEntitySetsAndSingletons
private void BuildEntitySetsAndSingletons(InvocationContext context, EdmModel model)
{
var configuration = context.ApiContext.Configuration;
foreach (var property in this.publicProperties)
{
if (configuration.IsPropertyIgnored(property.Name))
{
continue;
}
var isEntitySet = IsEntitySetProperty(property);
if (!isEntitySet)
{
if (!IsSingletonProperty(property))
{
continue;
}
}
var propertyType = property.PropertyType;
if (isEntitySet)
{
propertyType = propertyType.GetGenericArguments()[0];
}
var entityType = model.FindDeclaredType(propertyType.FullName) as IEdmEntityType;
if (entityType == null)
{
// Skip property whose entity type has not been declared yet.
continue;
}
var container = model.EnsureEntityContainer(this.targetType);
if (isEntitySet)
{
if (container.FindEntitySet(property.Name) == null)
{
this.entitySetProperties.Add(property);
var addedEntitySet = container.AddEntitySet(property.Name, entityType);
this.addedNavigationSources.Add(addedEntitySet);
}
}
else
{
if (container.FindSingleton(property.Name) == null)
{
this.singletonProperties.Add(property);
var addedSingleton = container.AddSingleton(property.Name, entityType);
this.addedNavigationSources.Add(addedSingleton);
}
}
}
}
示例2: GetModelAsync
/// <inheritdoc/>
public async Task<IEdmModel> GetModelAsync(InvocationContext context, CancellationToken cancellationToken)
{
Ensure.NotNull(context, "context");
IEdmModel modelReturned = await GetModelReturnedByInnerHandlerAsync(context, cancellationToken);
if (modelReturned == null)
{
// There is no model returned so return an empty model.
var emptyModel = new EdmModel();
emptyModel.EnsureEntityContainer(ModelCache.targetType);
return emptyModel;
}
EdmModel edmModel = modelReturned as EdmModel;
if (edmModel == null)
{
// The model returned is not an EDM model.
return modelReturned;
}
ModelCache.ScanForDeclaredPublicProperties();
ModelCache.BuildEntitySetsAndSingletons(context, edmModel);
ModelCache.AddNavigationPropertyBindings(edmModel);
return edmModel;
}
示例3: BuildFunctions
private void BuildFunctions(EdmModel model)
{
foreach (FunctionMethodInfo functionInfo in this.functionInfos)
{
var returnTypeReference = GetReturnTypeReference(functionInfo.Method.ReturnType, model);
ParameterInfo bindingParameter;
bool isBound = TryGetBindingParameter(functionInfo.Method, model, out bindingParameter);
var function = new EdmFunction(
functionInfo.Namespace,
functionInfo.Name,
returnTypeReference,
isBound,
BuildEntitySetPathExpression(returnTypeReference, bindingParameter),
functionInfo.IsComposable);
BuildOperationParameters(function, functionInfo.Method, model);
model.AddElement(function);
if (!isBound)
{
var entitySetReferenceExpression = BuildEntitySetReferenceExpression(
model, functionInfo.EntitySet, returnTypeReference);
var entityContainer = model.EnsureEntityContainer(this.targetType);
entityContainer.AddFunctionImport(
function.Name, function, entitySetReferenceExpression);
}
}
}