protected IQueryableCollection GetQueryableCollection(string entityName, string actualPropertyName, ISessionFactoryImplementor factory) { IPropertyMapping ownerMapping = (IPropertyMapping) factory.GetEntityPersister(entityName); IType type = ownerMapping.ToType(actualPropertyName); if (!type.IsCollectionType) { throw new MappingException( "Property path [" + entityName + "." + actualPropertyName + "] does not reference a collection" ); } string role = ((CollectionType) type).Role; try { return (IQueryableCollection) factory.GetCollectionPersister(role); } catch (InvalidCastException cce) { throw new QueryException("collection role is not queryable: " + role, cce); } catch (Exception e) { throw new QueryException("collection role not found: " + role, e); } }
/// <summary> /// Initialize the role of the collection. /// </summary> /// <param name="collection">The collection to be updated by reachability. </param> /// <param name="type">The type of the collection. </param> /// <param name="entity">The owner of the collection. </param> /// <param name="session">The session.</param> public static void ProcessReachableCollection(IPersistentCollection collection, CollectionType type, object entity, ISessionImplementor session) { collection.Owner = entity; CollectionEntry ce = session.PersistenceContext.GetCollectionEntry(collection); if (ce == null) { // refer to comment in StatefulPersistenceContext.addCollection() throw new HibernateException(string.Format("Found two representations of same collection: {0}", type.Role)); } // The CollectionEntry.isReached() stuff is just to detect any silly users // who set up circular or shared references between/to collections. if (ce.IsReached) { // We've been here before throw new HibernateException(string.Format("Found shared references to a collection: {0}", type.Role)); } ce.IsReached = true; ISessionFactoryImplementor factory = session.Factory; ICollectionPersister persister = factory.GetCollectionPersister(type.Role); ce.CurrentPersister = persister; ce.CurrentKey = type.GetKeyOfOwner(entity, session); //TODO: better to pass the id in as an argument? if (log.IsDebugEnabled) { log.Debug("Collection found: " + MessageHelper.CollectionInfoString(persister, collection, ce.CurrentKey, session) + ", was: " + MessageHelper.CollectionInfoString(ce.LoadedPersister, collection, ce.LoadedKey, session) + (collection.WasInitialized ? " (initialized)" : " (uninitialized)")); } PrepareCollectionForUpdate(collection, ce, session.EntityMode, factory); }
public System.Type GetAssociatedClass( ISessionFactoryImplementor factory ) { try { IQueryableCollection collectionPersister = (IQueryableCollection) factory.GetCollectionPersister( role ); if ( !collectionPersister.ElementType.IsEntityType ) { throw new MappingException( string.Format( "collection was not an association: {0}", collectionPersister.Role ) ) ; } return collectionPersister.ElementPersister.MappedClass; } catch ( InvalidCastException ice) { throw new MappingException( "collection role is not queryable " + role, ice ); } }
public IJoinable GetJoinable( ISessionFactoryImplementor factory ) { return (IJoinable) factory.GetCollectionPersister( role ); }
public IType GetElementType(ISessionFactoryImplementor factory) { return(factory.GetCollectionPersister(Role).ElementType); }
public IJoinable GetAssociatedJoinable(ISessionFactoryImplementor factory) { return((IJoinable)factory.GetCollectionPersister(role)); }
public string GetAssociatedEntityName(ISessionFactoryImplementor factory) { try { IQueryableCollection collectionPersister = (IQueryableCollection)factory.GetCollectionPersister(role); if (!collectionPersister.ElementType.IsEntityType) { throw new MappingException("collection was not an association: " + collectionPersister.Role); } return collectionPersister.ElementPersister.EntityName; } catch (InvalidCastException cce) { throw new MappingException("collection role is not queryable " + role, cce); } }
internal void AfterDeserialize(ISessionFactoryImplementor factory) { loadedPersister = factory.GetCollectionPersister(role); }
/// <summary> /// Initializes a new instance of <see cref="CollectionEntry"/> for initialized detached collections. /// </summary> /// <remarks> /// For initialized detached collections /// </remarks> internal CollectionEntry(IPersistentCollection collection, ISessionFactoryImplementor factory) { // detached collections that get found + reattached // during flush shouldn't be ignored ignore = false; loadedKey = collection.Key; SetLoadedPersister(factory.GetCollectionPersister(collection.Role)); snapshot = collection.StoredSnapshot; }
public override string ToString() { return("CollectionKey" + MessageHelper.CollectionInfoString(factory.GetCollectionPersister(role), key, factory)); }
public CustomLoader(ICustomQuery customQuery, ISessionFactoryImplementor factory) : base(factory) { sql = customQuery.SQL; querySpaces.AddAll(customQuery.QuerySpaces); namedParameterBindPoints = customQuery.NamedParameterBindPoints; List<IQueryable> entitypersisters = new List<IQueryable>(); List<int> entityowners = new List<int>(); List<IEntityAliases> entityaliases = new List<IEntityAliases>(); List<IQueryableCollection> collectionpersisters = new List<IQueryableCollection>(); List<int> collectionowners = new List<int>(); List<ICollectionAliases> collectionaliases = new List<ICollectionAliases>(); List<LockMode> lockmodes = new List<LockMode>(); List<IResultColumnProcessor> resultColumnProcessors = new List<IResultColumnProcessor>(); List<IReturn> nonScalarReturnList = new List<IReturn>(); List<IType> resulttypes = new List<IType>(); List<string> specifiedAliases = new List<string>(); int returnableCounter = 0; bool hasScalars = false; foreach (IReturn rtn in customQuery.CustomQueryReturns) { if (rtn is ScalarReturn) { ScalarReturn scalarRtn = (ScalarReturn) rtn; resulttypes.Add(scalarRtn.Type); specifiedAliases.Add(scalarRtn.ColumnAlias); resultColumnProcessors.Add(new ScalarResultColumnProcessor(scalarRtn.ColumnAlias, scalarRtn.Type)); hasScalars = true; } else if (rtn is RootReturn) { RootReturn rootRtn = (RootReturn) rtn; IQueryable persister = (IQueryable) factory.GetEntityPersister(rootRtn.EntityName); entitypersisters.Add(persister); lockmodes.Add(rootRtn.LockMode); resultColumnProcessors.Add(new NonScalarResultColumnProcessor(returnableCounter++)); nonScalarReturnList.Add(rtn); entityowners.Add(-1); resulttypes.Add(persister.Type); specifiedAliases.Add(rootRtn.Alias); entityaliases.Add(rootRtn.EntityAliases); querySpaces.AddAll(persister.QuerySpaces); } else if (rtn is CollectionReturn) { CollectionReturn collRtn = (CollectionReturn) rtn; string role = collRtn.OwnerEntityName + "." + collRtn.OwnerProperty; IQueryableCollection persister = (IQueryableCollection) factory.GetCollectionPersister(role); collectionpersisters.Add(persister); lockmodes.Add(collRtn.LockMode); resultColumnProcessors.Add(new NonScalarResultColumnProcessor(returnableCounter++)); nonScalarReturnList.Add(rtn); collectionowners.Add(-1); resulttypes.Add(persister.Type); specifiedAliases.Add(collRtn.Alias); collectionaliases.Add(collRtn.CollectionAliases); // determine if the collection elements are entities... IType elementType = persister.ElementType; if (elementType.IsEntityType) { IQueryable elementPersister = (IQueryable) ((EntityType) elementType).GetAssociatedJoinable(factory); entitypersisters.Add(elementPersister); entityowners.Add(-1); entityaliases.Add(collRtn.ElementEntityAliases); querySpaces.AddAll(elementPersister.QuerySpaces); } } else if (rtn is EntityFetchReturn) { EntityFetchReturn fetchRtn = (EntityFetchReturn) rtn; NonScalarReturn ownerDescriptor = fetchRtn.Owner; int ownerIndex = nonScalarReturnList.IndexOf(ownerDescriptor); entityowners.Add(ownerIndex); lockmodes.Add(fetchRtn.LockMode); IQueryable ownerPersister = DetermineAppropriateOwnerPersister(ownerDescriptor); EntityType fetchedType = (EntityType) ownerPersister.GetPropertyType(fetchRtn.OwnerProperty); string entityName = fetchedType.GetAssociatedEntityName(Factory); IQueryable persister = (IQueryable) factory.GetEntityPersister(entityName); entitypersisters.Add(persister); nonScalarReturnList.Add(rtn); specifiedAliases.Add(fetchRtn.Alias); entityaliases.Add(fetchRtn.EntityAliases); querySpaces.AddAll(persister.QuerySpaces); } else if (rtn is CollectionFetchReturn) { CollectionFetchReturn fetchRtn = (CollectionFetchReturn) rtn; NonScalarReturn ownerDescriptor = fetchRtn.Owner; int ownerIndex = nonScalarReturnList.IndexOf(ownerDescriptor); collectionowners.Add(ownerIndex); lockmodes.Add(fetchRtn.LockMode); IQueryable ownerPersister = DetermineAppropriateOwnerPersister(ownerDescriptor); string role = ownerPersister.EntityName + '.' + fetchRtn.OwnerProperty; IQueryableCollection persister = (IQueryableCollection) factory.GetCollectionPersister(role); collectionpersisters.Add(persister); nonScalarReturnList.Add(rtn); specifiedAliases.Add(fetchRtn.Alias); collectionaliases.Add(fetchRtn.CollectionAliases); // determine if the collection elements are entities... IType elementType = persister.ElementType; if (elementType.IsEntityType) { IQueryable elementPersister = (IQueryable) ((EntityType) elementType).GetAssociatedJoinable(factory); entitypersisters.Add(elementPersister); entityowners.Add(ownerIndex); entityaliases.Add(fetchRtn.ElementEntityAliases); querySpaces.AddAll(elementPersister.QuerySpaces); } } else { throw new HibernateException("unexpected custom query return type : " + rtn.GetType().FullName); } } entityPersisters = entitypersisters.ToArray(); entityOwners = entityowners.ToArray(); entityAliases = entityaliases.ToArray(); collectionPersisters = collectionpersisters.ToArray(); collectionOwners = collectionowners.ToArray(); collectionAliases = collectionaliases.ToArray(); lockModes = lockmodes.ToArray(); resultTypes = resulttypes.ToArray(); transformerAliases = specifiedAliases.ToArray(); rowProcessor = new ResultRowProcessor(hasScalars, resultColumnProcessors.ToArray()); }
/// <summary> /// Initializes a new instance of <see cref="CollectionEntry"/>. /// </summary> /// <param name="cs">The <see cref="ICollectionSnapshot"/> from another <see cref="ISession"/>.</param> /// <param name="factory">The <see cref="ISessionFactoryImplementor"/> that created this <see cref="ISession"/>.</param> /// <remarks> /// This takes an <see cref="ICollectionSnapshot"/> from another <see cref="ISession"/> and /// creates an entry for it in this <see cref="ISession"/> by copying the values from the /// <c>cs</c> parameter. /// </remarks> public CollectionEntry( ICollectionSnapshot cs, ISessionFactoryImplementor factory ) { this.dirty = cs.Dirty; this.snapshot = cs.Snapshot; this.loadedKey = cs.Key; this.initialized = true; // Detached collections that get found and reattached during flush // shouldn't be ignored this.ignore = false; SetLoadedPersister( factory.GetCollectionPersister( cs.Role ) ); }
internal void AfterDeserialize(ISessionFactoryImplementor factory) { loadedPersister = factory.GetCollectionPersister(role); }
public IType GetElementType( ISessionFactoryImplementor factory ) { return factory.GetCollectionPersister( Role ).ElementType; }
public CustomLoader( ICustomQuery customQuery, ISessionFactoryImplementor factory) : base(factory) { this.sql = customQuery.SQL; this.querySpaces.AddAll(customQuery.QuerySpaces); this.namedParameterBindPoints = customQuery.NamedParameterBindPoints; IList entityPersisters = new ArrayList(); IList entityOwners = new ArrayList(); IList entityAliases = new ArrayList(); IList collectionPersisters = new ArrayList(); IList collectionOwners = new ArrayList(); IList collectionAliases = new ArrayList(); IList lockModes = new ArrayList(); IList resultColumnProcessors = new ArrayList(); IList nonScalarReturnList = new ArrayList(); IList resultTypes = new ArrayList(); IList specifiedAliases = new ArrayList(); int returnableCounter = 0; bool hasScalars = false; foreach (IReturn rtn in customQuery.CustomQueryReturns) { if (rtn is ScalarReturn) { ScalarReturn scalarRtn = (ScalarReturn) rtn; resultTypes.Add(scalarRtn.Type); specifiedAliases.Add(scalarRtn.ColumnAlias); resultColumnProcessors.Add( new ScalarResultColumnProcessor( scalarRtn.ColumnAlias, scalarRtn.Type ) ); hasScalars = true; } else if (rtn is RootReturn) { RootReturn rootRtn = (RootReturn) rtn; IQueryable persister = (IQueryable) factory.GetEntityPersister(rootRtn.EntityName); entityPersisters.Add(persister); lockModes.Add(rootRtn.LockMode); resultColumnProcessors.Add(new NonScalarResultColumnProcessor(returnableCounter++)); nonScalarReturnList.Add(rtn); entityOwners.Add(-1); resultTypes.Add(persister.Type); specifiedAliases.Add(rootRtn.Alias); entityAliases.Add(rootRtn.EntityAliases); querySpaces.AddAll(persister.QuerySpaces); } else if (rtn is CollectionReturn) { CollectionReturn collRtn = (CollectionReturn) rtn; String role = collRtn.OwnerEntityName + "." + collRtn.OwnerProperty; IQueryableCollection persister = (IQueryableCollection) factory.GetCollectionPersister(role); collectionPersisters.Add(persister); lockModes.Add(collRtn.LockMode); resultColumnProcessors.Add(new NonScalarResultColumnProcessor(returnableCounter++)); nonScalarReturnList.Add(rtn); collectionOwners.Add(-1); resultTypes.Add(persister.Type); specifiedAliases.Add(collRtn.Alias); collectionAliases.Add(collRtn.CollectionAliases); // determine if the collection elements are entities... IType elementType = persister.ElementType; if (elementType.IsEntityType) { IQueryable elementPersister = (IQueryable) ((EntityType) elementType).GetAssociatedJoinable(factory); entityPersisters.Add(elementPersister); entityOwners.Add(-1); entityAliases.Add(collRtn.ElementEntityAliases); querySpaces.AddAll(elementPersister.QuerySpaces); } } else if (rtn is EntityFetchReturn) { EntityFetchReturn fetchRtn = (EntityFetchReturn) rtn; NonScalarReturn ownerDescriptor = fetchRtn.Owner; int ownerIndex = nonScalarReturnList.IndexOf(ownerDescriptor); entityOwners.Add(ownerIndex); lockModes.Add(fetchRtn.LockMode); IQueryable ownerPersister = DetermineAppropriateOwnerPersister(ownerDescriptor); EntityType fetchedType = (EntityType) ownerPersister.GetPropertyType(fetchRtn.OwnerProperty); string entityName = fetchedType.GetAssociatedEntityName(Factory); IQueryable persister = (IQueryable) factory.GetEntityPersister(entityName); entityPersisters.Add(persister); nonScalarReturnList.Add(rtn); specifiedAliases.Add(fetchRtn.Alias); entityAliases.Add(fetchRtn.EntityAliases); querySpaces.AddAll(persister.QuerySpaces); } else if (rtn is CollectionFetchReturn) { CollectionFetchReturn fetchRtn = (CollectionFetchReturn) rtn; NonScalarReturn ownerDescriptor = fetchRtn.Owner; int ownerIndex = nonScalarReturnList.IndexOf(ownerDescriptor); collectionOwners.Add(ownerIndex); lockModes.Add(fetchRtn.LockMode); IQueryable ownerPersister = DetermineAppropriateOwnerPersister(ownerDescriptor); String role = ownerPersister.EntityName + '.' + fetchRtn.OwnerProperty; IQueryableCollection persister = (IQueryableCollection) factory.GetCollectionPersister(role); collectionPersisters.Add(persister); nonScalarReturnList.Add(rtn); specifiedAliases.Add(fetchRtn.Alias); collectionAliases.Add(fetchRtn.CollectionAliases); // determine if the collection elements are entities... IType elementType = persister.ElementType; if (elementType.IsEntityType) { IQueryable elementPersister = (IQueryable) ((EntityType) elementType).GetAssociatedJoinable(factory); entityPersisters.Add(elementPersister); entityOwners.Add(ownerIndex); entityAliases.Add(fetchRtn.ElementEntityAliases); querySpaces.AddAll(elementPersister.QuerySpaces); } } else { throw new HibernateException("unexpected custom query return type : " + rtn.GetType().FullName); } } this.entityPersisters = new IQueryable[entityPersisters.Count]; for (int i = 0; i < entityPersisters.Count; i++) { this.entityPersisters[i] = (IQueryable) entityPersisters[i]; } this.entityOwners = ArrayHelper.ToIntArray(entityOwners); this.entityAliases = new IEntityAliases[entityAliases.Count]; for (int i = 0; i < entityAliases.Count; i++) { this.entityAliases[i] = (IEntityAliases) entityAliases[i]; } this.collectionPersisters = new IQueryableCollection[collectionPersisters.Count]; for (int i = 0; i < collectionPersisters.Count; i++) { this.collectionPersisters[i] = (IQueryableCollection) collectionPersisters[i]; } this.collectionOwners = ArrayHelper.ToIntArray(collectionOwners); this.collectionAliases = new ICollectionAliases[collectionAliases.Count]; for (int i = 0; i < collectionAliases.Count; i++) { this.collectionAliases[i] = (ICollectionAliases) collectionAliases[i]; } this.lockModes = new LockMode[lockModes.Count]; for (int i = 0; i < lockModes.Count; i++) { this.lockModes[i] = (LockMode) lockModes[i]; } this.resultTypes = ArrayHelper.ToTypeArray(resultTypes); this.transformerAliases = ArrayHelper.ToStringArray(specifiedAliases); this.rowProcessor = new ResultRowProcessor( hasScalars, (ResultColumnProcessor[]) ArrayHelper.ToArray(resultColumnProcessors, typeof(ResultColumnProcessor)) ); }
public CustomLoader(ICustomQuery customQuery, ISessionFactoryImplementor factory) : base(factory) { sql = customQuery.SQL; querySpaces.UnionWith(customQuery.QuerySpaces); parametersSpecifications = customQuery.CollectedParametersSpecifications.ToList(); List <IQueryable> entitypersisters = new List <IQueryable>(); List <int> entityowners = new List <int>(); List <IEntityAliases> entityaliases = new List <IEntityAliases>(); List <IQueryableCollection> collectionpersisters = new List <IQueryableCollection>(); List <int> collectionowners = new List <int>(); List <ICollectionAliases> collectionaliases = new List <ICollectionAliases>(); List <LockMode> lockmodes = new List <LockMode>(); List <IResultColumnProcessor> resultColumnProcessors = new List <IResultColumnProcessor>(); List <IReturn> nonScalarReturnList = new List <IReturn>(); List <IType> resulttypes = new List <IType>(); List <string> specifiedAliases = new List <string>(); List <bool> includeInResultRowList = new List <bool>(); int returnableCounter = 0; bool hasScalars = false; foreach (IReturn rtn in customQuery.CustomQueryReturns) { if (rtn is ScalarReturn) { ScalarReturn scalarRtn = (ScalarReturn)rtn; resulttypes.Add(scalarRtn.Type); specifiedAliases.Add(scalarRtn.ColumnAlias); resultColumnProcessors.Add(new ScalarResultColumnProcessor(scalarRtn.ColumnAlias, scalarRtn.Type)); includeInResultRowList.Add(true); hasScalars = true; } else if (rtn is RootReturn) { RootReturn rootRtn = (RootReturn)rtn; IQueryable persister = (IQueryable)factory.GetEntityPersister(rootRtn.EntityName); entitypersisters.Add(persister); lockmodes.Add(rootRtn.LockMode); resultColumnProcessors.Add(new NonScalarResultColumnProcessor(returnableCounter++)); nonScalarReturnList.Add(rtn); entityowners.Add(-1); resulttypes.Add(persister.Type); specifiedAliases.Add(rootRtn.Alias); entityaliases.Add(rootRtn.EntityAliases); querySpaces.UnionWith(persister.QuerySpaces); includeInResultRowList.Add(true); } else if (rtn is CollectionReturn) { CollectionReturn collRtn = (CollectionReturn)rtn; string role = collRtn.OwnerEntityName + "." + collRtn.OwnerProperty; IQueryableCollection persister = (IQueryableCollection)factory.GetCollectionPersister(role); collectionpersisters.Add(persister); lockmodes.Add(collRtn.LockMode); resultColumnProcessors.Add(new NonScalarResultColumnProcessor(returnableCounter++)); nonScalarReturnList.Add(rtn); collectionowners.Add(-1); resulttypes.Add(persister.Type); specifiedAliases.Add(collRtn.Alias); collectionaliases.Add(collRtn.CollectionAliases); // determine if the collection elements are entities... IType elementType = persister.ElementType; if (elementType.IsEntityType) { IQueryable elementPersister = (IQueryable)((EntityType)elementType).GetAssociatedJoinable(factory); entitypersisters.Add(elementPersister); entityowners.Add(-1); entityaliases.Add(collRtn.ElementEntityAliases); querySpaces.UnionWith(elementPersister.QuerySpaces); } includeInResultRowList.Add(true); } else if (rtn is EntityFetchReturn) { EntityFetchReturn fetchRtn = (EntityFetchReturn)rtn; NonScalarReturn ownerDescriptor = fetchRtn.Owner; int ownerIndex = nonScalarReturnList.IndexOf(ownerDescriptor); entityowners.Add(ownerIndex); lockmodes.Add(fetchRtn.LockMode); IQueryable ownerPersister = DetermineAppropriateOwnerPersister(ownerDescriptor); EntityType fetchedType = (EntityType)ownerPersister.GetPropertyType(fetchRtn.OwnerProperty); string entityName = fetchedType.GetAssociatedEntityName(Factory); IQueryable persister = (IQueryable)factory.GetEntityPersister(entityName); entitypersisters.Add(persister); nonScalarReturnList.Add(rtn); specifiedAliases.Add(fetchRtn.Alias); entityaliases.Add(fetchRtn.EntityAliases); querySpaces.UnionWith(persister.QuerySpaces); includeInResultRowList.Add(false); } else if (rtn is CollectionFetchReturn) { CollectionFetchReturn fetchRtn = (CollectionFetchReturn)rtn; NonScalarReturn ownerDescriptor = fetchRtn.Owner; int ownerIndex = nonScalarReturnList.IndexOf(ownerDescriptor); collectionowners.Add(ownerIndex); lockmodes.Add(fetchRtn.LockMode); IQueryable ownerPersister = DetermineAppropriateOwnerPersister(ownerDescriptor); string role = ownerPersister.EntityName + '.' + fetchRtn.OwnerProperty; IQueryableCollection persister = (IQueryableCollection)factory.GetCollectionPersister(role); collectionpersisters.Add(persister); nonScalarReturnList.Add(rtn); specifiedAliases.Add(fetchRtn.Alias); collectionaliases.Add(fetchRtn.CollectionAliases); // determine if the collection elements are entities... IType elementType = persister.ElementType; if (elementType.IsEntityType) { IQueryable elementPersister = (IQueryable)((EntityType)elementType).GetAssociatedJoinable(factory); entitypersisters.Add(elementPersister); entityowners.Add(ownerIndex); entityaliases.Add(fetchRtn.ElementEntityAliases); querySpaces.UnionWith(elementPersister.QuerySpaces); } includeInResultRowList.Add(false); } else { throw new HibernateException("unexpected custom query return type : " + rtn.GetType().FullName); } } entityPersisters = entitypersisters.ToArray(); entityOwners = entityowners.ToArray(); entityAliases = entityaliases.ToArray(); collectionPersisters = collectionpersisters.ToArray(); collectionOwners = collectionowners.ToArray(); collectionAliases = collectionaliases.ToArray(); lockModes = lockmodes.ToArray(); resultTypes = resulttypes.ToArray(); transformerAliases = specifiedAliases.ToArray(); rowProcessor = new ResultRowProcessor(hasScalars, resultColumnProcessors.ToArray()); includeInResultRow = includeInResultRowList.ToArray(); }
public void CommonRegionHasOneUniqueCacheAndExpectedConcurrency(bool withPrefix) { const string prefix = "Prefix"; const string region = "Common"; var fullRegion = (withPrefix ? prefix + "." : "") + region; ISessionFactoryImplementor sfi = null; if (withPrefix) { cfg.SetProperty(Environment.CacheRegionPrefix, prefix); } try { sfi = withPrefix ? BuildSessionFactory() : Sfi; var commonRegionCache = sfi.GetSecondLevelCacheRegion(fullRegion); var entityAName = typeof(EntityA).FullName; var entityAConcurrencyCache = sfi.GetEntityPersister(entityAName).Cache; var entityACache = entityAConcurrencyCache.Cache; var entityBName = typeof(EntityB).FullName; var entityBConcurrencyCache = sfi.GetEntityPersister(entityBName).Cache; var entityBCache = entityBConcurrencyCache.Cache; var relatedAConcurrencyCache = sfi.GetCollectionPersister(StringHelper.Qualify(entityAName, nameof(EntityA.Related))).Cache; var relatedACache = relatedAConcurrencyCache.Cache; var relatedBConcurrencyCache = sfi.GetCollectionPersister(StringHelper.Qualify(entityBName, nameof(EntityB.Related))).Cache; var relatedBCache = relatedBConcurrencyCache.Cache; var queryCache = sfi.GetQueryCache(region).Cache; Assert.Multiple( () => { Assert.That(commonRegionCache.RegionName, Is.EqualTo(fullRegion), "Unexpected region name for common region"); Assert.That(entityACache.RegionName, Is.EqualTo(fullRegion), "Unexpected region name for EntityA"); Assert.That(entityBCache.RegionName, Is.EqualTo(fullRegion), "Unexpected region name for EntityB"); Assert.That(relatedACache.RegionName, Is.EqualTo(fullRegion), "Unexpected region name for RelatedA"); Assert.That(relatedBCache.RegionName, Is.EqualTo(fullRegion), "Unexpected region name for RelatedB"); Assert.That(queryCache.RegionName, Is.EqualTo(fullRegion), "Unexpected region name for query cache"); }); Assert.Multiple( () => { Assert.That(entityAConcurrencyCache, Is.InstanceOf <ReadWriteCache>(), "Unexpected concurrency for EntityA"); Assert.That(relatedAConcurrencyCache, Is.InstanceOf <NonstrictReadWriteCache>(), "Unexpected concurrency for RelatedA"); Assert.That(entityBConcurrencyCache, Is.InstanceOf <ReadOnlyCache>(), "Unexpected concurrency for EntityB"); Assert.That(relatedBConcurrencyCache, Is.InstanceOf <ReadWriteCache>(), "Unexpected concurrency for RelatedB"); Assert.That(entityACache, Is.SameAs(commonRegionCache), "Unexpected cache for EntityA"); Assert.That(entityBCache, Is.SameAs(commonRegionCache), "Unexpected cache for EntityB"); Assert.That(relatedACache, Is.SameAs(commonRegionCache), "Unexpected cache for RelatedA"); Assert.That(relatedBCache, Is.SameAs(commonRegionCache), "Unexpected cache for RelatedB"); Assert.That(queryCache, Is.SameAs(commonRegionCache), "Unexpected cache for query cache"); }); } finally { if (withPrefix) { cfg.Properties.Remove(Environment.CacheRegionPrefix); sfi?.Dispose(); } } }