// Constructors

        /// <summary>
        /// Initializes a new instance of this class.
        /// </summary>
        /// <param name="owner">Persistent this entity set belongs to.</param>
        /// <param name="field">Field corresponds to this entity set.</param>
        protected EntitySetBase(Entity owner, FieldInfo field)
            : base(owner.Session)
        {
            this.owner = owner;
            Field      = field;
            State      = new EntitySetState(this);
            var association = Field.Associations.Last();

            if (association.AuxiliaryType != null && association.IsMaster)
            {
                Domain domain   = Session.Domain;
                var    itemType = domain.Model.Types[Field.ItemType];
                auxilaryTypeKeyTransform = new CombineTransform(
                    false,
                    owner.TypeInfo.Key.TupleDescriptor,
                    itemType.Key.TupleDescriptor);
            }

            if (association.Multiplicity != Multiplicity.ManyToOne && association.Multiplicity != Multiplicity.OneToMany)
            {
                skipOwnerVersionChange = false;
            }
            else
            {
                skipOwnerVersionChange = Session.Domain.Configuration.VersioningConvention.DenyEntitySetOwnerVersionChange;
            }

            Initialize(WellKnownOrmTypes.EntitySetBase);
        }
        private int?GetItemIndex(EntitySetState state, Key key)
        {
            if (!state.IsFullyLoaded)
            {
                return(null);
            }
            if (!Session.EntityEvents.HasSubscribers)
            {
                return(null);
            }
            var subscriptionInfo = GetSubscription(EntityEventBroker.CollectionChangedEventKey);

            if (subscriptionInfo.Second == null)
            {
                return(null);
            }

            // Ok, it seems there is a reason
            // to waste linear time on calculating this...
            int i = 0;

            foreach (var cachedKey in state)
            {
                if (key == cachedKey)
                {
                    return(i);
                }
                i++;
            }
            return(null);
        }
Example #3
0
        internal bool LookupStateInCache(Key key, FieldInfo fieldInfo, out EntitySetState entitySetState)
        {
            var entityState = EntityStateCache[key, false];

            if (entityState != null)
            {
                var entity = entityState.Entity;
                if (entity != null)
                {
                    var entitySet = (EntitySetBase)entity.GetFieldValue(fieldInfo);
                    if (entitySet.CheckStateIsLoaded())
                    {
                        entitySetState = entitySet.State;
                        return(true);
                    }
                }
            }
            entitySetState = null;
            return(false);
        }
Example #4
0
 internal override bool LookupState(Key key, FieldInfo fieldInfo, out EntitySetState entitySetState)
 {
     return(ChainedHandler.LookupState(key, fieldInfo, out entitySetState));
 }
 internal virtual bool LookupState(Key key, FieldInfo fieldInfo, out EntitySetState entitySetState)
 {
     return(Session.LookupStateInCache(key, fieldInfo, out entitySetState));
 }