Beispiel #1
0
        protected virtual void AddRelation <T, TRelation>(ICollectionEntityGraphNode <T, TRelation> node, Frame frame)
        {
            var query      = this.Database.QueryCache.Add(node.Relation.MappingTable);
            var parameters = this.GetParameters(frame, node.Relation);

            this.Database.Execute(query, parameters, this.Transaction);
        }
Beispiel #2
0
        protected virtual void DeleteRelation <T, TRelation>(ICollectionEntityGraphNode <T, TRelation> node, Frame frame)
        {
            var query = this.Database.QueryCache.GetOrAdd(
                new DatabaseQueryTableCacheKey(
                    node.Relation.MappingTable,
                    DatabaseQueryCache.DELETE
                    ),
                () =>
            {
                var builder = this.Database.QueryFactory.Build();
                var columns = node.Relation.Expression.GetColumnMap();
                builder.Delete.Touch();
                builder.Source.AddTable(node.Relation.MappingTable);
                builder.Filter.AddColumns(columns[node.Relation.MappingTable]);
                return(builder.Build());
            }
                );
            var parameters = this.GetParameters(frame, node.Relation);

            this.Database.Execute(query, parameters, this.Transaction);
        }
Beispiel #3
0
        protected virtual EntityAction OnVisit <T, TRelation>(ICollectionEntityGraphNode <T, TRelation> node, Frame <T> frame)
        {
            var result     = EntityAction.None;
            var difference = EntityDiffer.Instance.GetDifference <T, TRelation>(node.Relation, frame.Persisted, frame.Updated);

            foreach (var element in difference.Added.Concat(difference.Updated))
            {
                result |= this.OnVisit(node, new Frame <TRelation>(frame, element.Persisted, element.Updated));
                if (result.HasFlag(EntityAction.Added) && node.Relation.Flags.GetMultiplicity() == RelationFlags.ManyToMany)
                {
                    this.AddRelation(node, new Frame <TRelation>(frame, element.Persisted, element.Updated));
                }
            }
            foreach (var element in difference.Deleted)
            {
                if (node.Relation.Flags.GetMultiplicity() == RelationFlags.ManyToMany)
                {
                    this.DeleteRelation(node, new Frame <TRelation>(frame, element.Persisted, element.Updated));
                }
                result |= this.OnVisit(node, new Frame <TRelation>(frame, element.Persisted, element.Updated));
            }
            return(result);
        }
Beispiel #4
0
        protected virtual void OnVisit <T, TRelation>(IEntityEnumeratorBuffer buffer, IEntityEnumeratorSink sink, ICollectionEntityGraphNode <T, TRelation> node)
        {
            if (!buffer.Exists(node.Parent.Table) || !buffer.Exists(node.Table))
            {
                return;
            }
            var parent   = (T)buffer.Get(node.Parent.Table);
            var child    = (TRelation)buffer.Get(node.Table);
            var sequence = node.Relation.Accessor.Get(parent);

            if (sequence == null)
            {
                throw new NotImplementedException();
            }
            else
            {
                sequence.Add(child);
            }
        }