public BytecodeEnhancementMetadataNonPocoImpl(string entityName)
 {
     EntityName                    = entityName;
     LazyPropertiesMetadata        = LazyPropertiesMetadata.NonEnhanced(entityName);
     UnwrapProxyPropertiesMetadata = UnwrapProxyPropertiesMetadata.NonEnhanced(entityName);
     _errorMessage                 = $"Entity [{entityName}] is non-poco, and therefore not instrumented";
 }
예제 #2
0
        public static IBytecodeEnhancementMetadata From(
            PersistentClass persistentClass,
            ICollection <LazyPropertyDescriptor> lazyPropertyDescriptors,
            ICollection <UnwrapProxyPropertyDescriptor> unwrapProxyPropertyDescriptors)
        {
            var mappedClass            = persistentClass.MappedClass;
            var enhancedForLazyLoading = lazyPropertyDescriptors?.Count > 0 || unwrapProxyPropertyDescriptors?.Count > 0;

            // We have to check all subclasses if any of them is enhanced for lazy loading as the
            // root class will be enhanced when any of the subclasses is enhanced, even if it
            // does not have any lazy properties.
            // If we do not check the subclasses, where the root-entity has no lazy properties
            // we will eager-load/double-load those properties (NH2488).
            if (!enhancedForLazyLoading)
            {
                foreach (var persistentSubclass in persistentClass.SubclassClosureIterator)
                {
                    enhancedForLazyLoading |= IsEnhancedForLazyLoading(persistentSubclass);
                    if (enhancedForLazyLoading)
                    {
                        break;
                    }
                }
            }

            var lazyPropertiesMetadata = enhancedForLazyLoading
                                ? LazyPropertiesMetadata.From(persistentClass.EntityName, lazyPropertyDescriptors)
                                : LazyPropertiesMetadata.NonEnhanced(persistentClass.EntityName);

            var unwrapProxyPropertiesMetadata = enhancedForLazyLoading
                                ? UnwrapProxyPropertiesMetadata.From(persistentClass.EntityName, unwrapProxyPropertyDescriptors)
                                : UnwrapProxyPropertiesMetadata.NonEnhanced(persistentClass.EntityName);

            return(new BytecodeEnhancementMetadataPocoImpl(
                       persistentClass.EntityName,
                       mappedClass,
                       enhancedForLazyLoading,
                       lazyPropertiesMetadata,
                       unwrapProxyPropertiesMetadata
                       ));
        }