コード例 #1
0
        public virtual IList <EntityType> QueryResultForChildrenOnly(IList <EntityType> existing)
        {
            object parms;

            IList <EntityType> res = new List <EntityType>();

            if (_children.Count < 1)
            {
                return(res);
            }

            var query = GetSqlForChildQueriesOnly(out parms);

            if (_children.Count > 0)
            {
                res = _executer.Execute(_connectionStringName, query.ToString(), parms, new Func <SqlMapper.GridReader, IList <EntityType> >(f => LoadChildEntities(existing, f)));
            }

            return(res);
        }
コード例 #2
0
        public virtual int Execute(ScriptContext context)
        {
            foreach (var d in _tasks)
            {
                if (d.TaskType == ActionType.Update && d.Entity != null && !d.Entity.IsDirty)
                {
                    context.Add(d.Entity.GetHashCode());
                    continue;
                }

                UpdateIdsFromReferences(_cascades, d.Entity);

                if (d.Entity != null)
                {
                    context.Add(d.Entity.GetHashCode());
                }
                else if (d.Entities != null)
                {
                    foreach (var e in d.Entities)
                    {
                        context.Add(e.GetHashCode());
                    }
                }
                else
                {
                    context.Add(d.Queries.First().FieldName.GetHashCode());
                }

                if (_cascades.Count > 0)
                {
                    if (d.TaskType == ActionType.Remove)
                    {
                        if (d.Entity != null)
                        {
                            RemoveRelations(d.Entity, context);
                        }
                        else if (d.Entities.Count > 0)
                        {
                            foreach (var e in d.Entities)
                            {
                                RemoveRelations(e, context);
                            }
                        }
                    }
                    else if (d.Entity != null)
                    {
                        CascadeRelations(d.Entity, context);
                    }
                }
            }

            var count = 0;

            foreach (var p in _parents)
            {
                count += p.Item1.Execute(context);
                UpdateIdsFromReferences(_cascades, p.Item2);
            }

            foreach (var c in _children.Where(c => c.Item1.HasDeletes()))
            {
                count += c.Item1.Execute(context);
                UpdateIdsFromReferences(_cascades, c.Item2);
            }

            //if the entity was already inserted via cascade since the task was initiated, remove it.
            _tasks.RemoveAll(d => d.Entity != null && d.TaskType == ActionType.Add && !d.Entity.IsDirty);
            //_tasks.RemoveAll(d => d.Entity != null && d.TaskType != ActionType.Remove && !d.Entity.IsDirty);

            if (_tasks.Count < 1)
            {
                return(count);
            }

            object parms;

            var sql = GetSql(out parms);

            count += _executer.Execute <IdType>(_connectionStringName, sql, parms, SetIds);

            foreach (var d in _tasks)
            {
                if (d.Entity != null)
                {
                    d.Entity.IsDirty = false;
                }
            }

            foreach (var c in _children.Where(c => !c.Item1.HasDeletes()))
            {
                if (c.Item2 != null)
                {
                    UpdateIdsFromReferences(_cascades, c.Item2);
                }

                count += c.Item1.Execute(context);
            }

            return(count);
        }