public void RegisterEntitySetTask(EntityState ownerState, PrefetchFieldDescriptor referencingFieldDescriptor)
        {
            if (entitySetTasks == null)
            {
                entitySetTasks = new Dictionary <FieldInfo, EntitySetTask>();
            }
            if (RootEntityContainer == null)
            {
                AddEntityColumns(Key.TypeReference.Type.Fields
                                 .Where(field => field.IsPrimaryKey || field.IsSystem).SelectMany(field => field.Columns));
            }
            EntitySetTask task;

            if (!entitySetTasks.TryGetValue(referencingFieldDescriptor.Field, out task))
            {
                entitySetTasks.Add(referencingFieldDescriptor.Field,
                                   new EntitySetTask(Key, referencingFieldDescriptor, ownerState != null, Manager));
            }
            else if (task.ItemCountLimit == null)
            {
                return;
            }
            else if (referencingFieldDescriptor.EntitySetItemCountLimit == null ||
                     task.ItemCountLimit < referencingFieldDescriptor.EntitySetItemCountLimit)
            {
                entitySetTasks[referencingFieldDescriptor.Field] =
                    new EntitySetTask(Key, referencingFieldDescriptor, ownerState != null, Manager);
            }
        }
 private void RegisterFetchByUnknownForeignKey(PrefetchFieldDescriptor referencingFieldDescriptor)
 {
     if (referencedEntityContainers == null)
     {
         referencedEntityContainers = new Dictionary <FieldInfo, ReferencedEntityContainer>();
     }
     referencedEntityContainers.Add(referencingFieldDescriptor.Field, new ReferencedEntityContainer(Key,
                                                                                                    referencingFieldDescriptor, exactType, Manager));
 }
        // Constructors

        public ReferencedEntityContainer(Key ownerKey, PrefetchFieldDescriptor referencingFieldDescriptor,
                                         bool isOwnerTypeKnown, PrefetchManager manager)
            : base(null, referencingFieldDescriptor.Field.Associations.Last().TargetType, true, manager)
        {
            ArgumentValidator.EnsureArgumentNotNull(referencingFieldDescriptor, "referencingFieldDescriptor");
            ArgumentValidator.EnsureArgumentNotNull(ownerKey, "ownerKey");
            this.ownerKey = ownerKey;
            this.referencingFieldDescriptor = referencingFieldDescriptor;
            this.isOwnerTypeKnown           = isOwnerTypeKnown;
        }
예제 #4
0
        // Constructors

        public EntitySetTask(Key ownerKey, PrefetchFieldDescriptor referencingFieldDescriptor, bool isOwnerCached,
                             PrefetchManager manager)
        {
            ArgumentValidator.EnsureArgumentNotNull(ownerKey, "ownerKey");
            ArgumentValidator.EnsureArgumentNotNull(referencingFieldDescriptor, "referencingFieldDescriptor");
            ArgumentValidator.EnsureArgumentNotNull(manager, "processor");

            this.ownerKey = ownerKey;
            this.referencingFieldDescriptor = referencingFieldDescriptor;
            this.isOwnerCached = isOwnerCached;
            ItemCountLimit     = referencingFieldDescriptor.EntitySetItemCountLimit;
            this.manager       = manager;
            cacheKey           = new CacheKey(ReferencingField, ItemCountLimit);
        }
        private void RegisterFetchByKnownForeignKey(PrefetchFieldDescriptor referencingFieldDescriptor,
                                                    EntityState ownerState)
        {
            var association        = referencingFieldDescriptor.Field.Associations.Last();
            var referencedKeyTuple = association
                                     .ExtractForeignKey(ownerState.Type, ownerState.Tuple);
            var referencedKeyTupleState = referencedKeyTuple.GetFieldStateMap(TupleFieldState.Null);

            for (var i = 0; i < referencedKeyTupleState.Length; i++)
            {
                if (referencedKeyTupleState[i])
                {
                    return;
                }
            }
            var session       = Manager.Owner.Session;
            var referencedKey = Key.Create(session.Domain, session.StorageNodeId,
                                           association.TargetType, TypeReferenceAccuracy.BaseType,
                                           referencedKeyTuple);
            var      targetType       = association.TargetType;
            var      areToNotifyOwner = true;
            TypeInfo exactReferencedType;
            var      hasExactTypeBeenGotten = PrefetchHelper.TryGetExactKeyType(referencedKey, Manager,
                                                                                out exactReferencedType);

            if (hasExactTypeBeenGotten != null)
            {
                if (hasExactTypeBeenGotten.Value)
                {
                    targetType       = exactReferencedType;
                    areToNotifyOwner = false;
                }
            }
            else
            {
                return;
            }
            var fieldsToBeLoaded = PrefetchHelper
                                   .GetCachedDescriptorsForFieldsLoadedByDefault(session.Domain, targetType);
            var graphContainer = Manager.SetUpContainers(referencedKey, targetType,
                                                         fieldsToBeLoaded, true, null, true);

            if (areToNotifyOwner)
            {
                graphContainer.RootEntityContainer.SetParametersOfReference(referencingFieldDescriptor, referencedKey);
            }
        }
 public void RegisterReferencedEntityContainer(
     EntityState ownerState, PrefetchFieldDescriptor referencingFieldDescriptor)
 {
     if (referencedEntityContainers != null &&
         referencedEntityContainers.ContainsKey(referencingFieldDescriptor.Field))
     {
         return;
     }
     if (!AreAllForeignKeyColumnsLoaded(ownerState, referencingFieldDescriptor.Field))
     {
         RegisterFetchByUnknownForeignKey(referencingFieldDescriptor);
     }
     else
     {
         RegisterFetchByKnownForeignKey(referencingFieldDescriptor, ownerState);
     }
 }
 /// <inheritdoc/>
 public bool Equals(PrefetchFieldDescriptor other)
 {
     return(Equals(other.Field, Field));
 }
 public void SetParametersOfReference(PrefetchFieldDescriptor referencingField, Key key)
 {
     referencingFieldDescriptor = referencingField;
     ownerKey = key;
 }