本文整理汇总了C#中IEdmModel.GetEpmCache方法的典型用法代码示例。如果您正苦于以下问题:C# IEdmModel.GetEpmCache方法的具体用法?C# IEdmModel.GetEpmCache怎么用?C# IEdmModel.GetEpmCache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEdmModel
的用法示例。
在下文中一共展示了IEdmModel.GetEpmCache方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckEntityPropertyMapping
internal static void CheckEntityPropertyMapping(ODataVersion version, IEdmEntityType entityType, IEdmModel model)
{
ODataEntityPropertyMappingCache epmCache = model.GetEpmCache(entityType);
if ((epmCache != null) && (version < epmCache.EpmTargetTree.MinimumODataProtocolVersion))
{
throw new ODataException(Microsoft.Data.OData.Strings.ODataVersionChecker_EpmVersionNotSupported(entityType.ODataFullName(), ODataUtils.ODataVersionToString(epmCache.EpmTargetTree.MinimumODataProtocolVersion), ODataUtils.ODataVersionToString(version)));
}
}
示例2: EnsureEpmCacheInternal
private static ODataEntityPropertyMappingCache EnsureEpmCacheInternal(IEdmModel model, IEdmEntityType entityType, int maxMappingCount, out bool cacheModified)
{
cacheModified = false;
if (entityType == null)
{
return null;
}
IEdmEntityType type = entityType.BaseEntityType();
ODataEntityPropertyMappingCache baseCache = null;
if (type != null)
{
baseCache = EnsureEpmCacheInternal(model, type, maxMappingCount, out cacheModified);
}
ODataEntityPropertyMappingCache epmCache = model.GetEpmCache(entityType);
if (model.HasOwnOrInheritedEpm(entityType))
{
ODataEntityPropertyMappingCollection entityPropertyMappings = model.GetEntityPropertyMappings(entityType);
if (!(((epmCache == null) || cacheModified) || epmCache.IsDirty(entityPropertyMappings)))
{
return epmCache;
}
cacheModified = true;
int totalMappingCount = ValidationUtils.ValidateTotalEntityPropertyMappingCount(baseCache, entityPropertyMappings, maxMappingCount);
epmCache = new ODataEntityPropertyMappingCache(entityPropertyMappings, model, totalMappingCount);
try
{
epmCache.BuildEpmForType(entityType, entityType);
epmCache.EpmSourceTree.Validate(entityType);
model.SetAnnotationValue<ODataEntityPropertyMappingCache>(entityType, epmCache);
return epmCache;
}
catch
{
model.RemoveEpmCache(entityType);
throw;
}
}
if (epmCache != null)
{
cacheModified = true;
model.RemoveEpmCache(entityType);
}
return epmCache;
}
示例3: EnsureEpmCacheInternal
/// <summary>
/// Ensures that an up-to-date EPM cache exists for the specified <paramref name="entityType"/>.
/// If no cache exists, a new one will be created based on the public mappings (if any).
/// If the public mappings have changed (and the cache is thus dirty), the method re-constructs the cache.
/// If all public mappings have been removed, the method also removes the EPM cache.
/// </summary>
/// <param name="model">IEdmModel instance containing the annotations.</param>
/// <param name="entityType">IEdmEntityType instance for which to ensure the EPM cache.</param>
/// <param name="maxMappingCount">The maximum allowed number of entity property mappings
/// for a given entity type (on the type itself and all its base types).</param>
/// <param name="cacheModified">true if the cache was modified; otherwise false.</param>
/// <returns>An instance of <see cref="ODataEntityPropertyMappingCache"/>, if there are any EPM mappings for the given entity type, otherwise returns null.</returns>
private static ODataEntityPropertyMappingCache EnsureEpmCacheInternal(
IEdmModel model,
IEdmEntityType entityType,
int maxMappingCount,
out bool cacheModified)
{
cacheModified = false;
if (entityType == null)
{
return null;
}
// Make sure the EPM of the base type is initialized.
IEdmEntityType baseEntityType = entityType.BaseEntityType();
ODataEntityPropertyMappingCache baseCache = null;
if (baseEntityType != null)
{
baseCache = EnsureEpmCacheInternal(model, baseEntityType, maxMappingCount, out cacheModified);
}
ODataEntityPropertyMappingCache epmCache = model.GetEpmCache(entityType);
if (model.HasOwnOrInheritedEpm(entityType))
{
ODataEntityPropertyMappingCollection mappings = model.GetEntityPropertyMappings(entityType);
bool needToBuildCache = epmCache == null || cacheModified || epmCache.IsDirty(mappings);
if (needToBuildCache)
{
cacheModified = true;
int totalMappingCount = ValidationUtils.ValidateTotalEntityPropertyMappingCount(baseCache, mappings, maxMappingCount);
epmCache = new ODataEntityPropertyMappingCache(mappings, model, totalMappingCount);
// Build the EPM tree and validate it
try
{
epmCache.BuildEpmForType(entityType, entityType);
epmCache.EpmSourceTree.Validate(entityType);
epmCache.EpmTargetTree.Validate();
// We set the annotation here, so if anything fails during
// building of the cache the annotation will not even be set so
// not leaving the type in an inconsistent state.
model.SetAnnotationValue(entityType, epmCache);
}
catch
{
// Remove an existing EPM cache if it is dirty to make sure we don't leave
// stale caches in case building of the cache fails.
// NOTE: we do this in the catch block to ensure that we always make a single
// SetAnnotation call to either set or clear the existing annotation
// since the SetAnnotation method is thread-safe
model.RemoveEpmCache(entityType);
throw;
}
}
}
else
{
if (epmCache != null)
{
// remove an existing EPM cache if the mappings have been removed from the type
cacheModified = true;
model.RemoveEpmCache(entityType);
}
}
return epmCache;
}
示例4: CheckEntityPropertyMapping
/// <summary>
/// Check whether the EPM on the specified entity type is supported in the specified version.
/// </summary>
/// <param name="version">The version to check.</param>
/// <param name="entityType">The entity type to check.</param>
/// <param name="model">The model containing annotations for the entity type.</param>
internal static void CheckEntityPropertyMapping(ODataVersion version, IEdmEntityType entityType, IEdmModel model)
{
DebugUtils.CheckNoExternalCallers();
Debug.Assert(entityType != null, "entityType != null");
Debug.Assert(model != null, "model != null");
ODataEntityPropertyMappingCache epmCache = model.GetEpmCache(entityType);
if (epmCache != null)
{
Debug.Assert(epmCache.EpmTargetTree != null, "If the EPM annotation is present the EPM tree must already be initialized.");
if (version < epmCache.EpmTargetTree.MinimumODataProtocolVersion)
{
throw new ODataException(
Strings.ODataVersionChecker_EpmVersionNotSupported(
entityType.ODataFullName(),
ODataUtils.ODataVersionToString(epmCache.EpmTargetTree.MinimumODataProtocolVersion),
ODataUtils.ODataVersionToString(version)));
}
}
}