Exemplo n.º 1
0
        private void ProcessEntry(ReferenceEntry referenceEntry)
        {
            if (!referenceEntry.IsLoaded)
            {
                referenceEntry.Load();
            }

            var dependentEntry = referenceEntry.CurrentValue;

            if (dependentEntry == null)
            {
                return;
            }

            switch (referenceEntry.Metadata.ForeignKey.DeleteBehavior)
            {
            // We only have to process changes in database,
            // about changes on the client side the ef core will take care.
            case DeleteBehavior.Cascade:
                Remove(dependentEntry);
                break;

            case DeleteBehavior.SetNull:
                SetNull(Entry(dependentEntry), referenceEntry.Metadata.ForeignKey);
                break;
                // Do nothing for other cases
            }
        }
Exemplo n.º 2
0
        public virtual void LoadReference <TProperty>(TEntity entity, Expression <Func <TEntity, TProperty> > member)
            where TProperty : class
        {
            Attach(entity);

            ReferenceEntry <TEntity, TProperty> reference = _dbContext.Entry(entity).Reference(member);

            if (reference.IsLoaded == false)
            {
                reference.Load();
            }
        }
Exemplo n.º 3
0
        public virtual void LoadReference <TProperty>(TDto dto, Expression <Func <TDto, TProperty> > member)
            where TProperty : class
        {
            try
            {
                Attach(dto);

                ReferenceEntry <TDto, TProperty> reference = _dbContext.Entry(dto).Reference(member);

                if (reference.IsLoaded == false)
                {
                    reference.Load();
                }
            }
            finally
            {
                Detach(dto);
            }
        }