Exemplo n.º 1
0
        public object Fetch(DatabaseCore accessor)
        {
            if (accessor == null)
            {
                return(null);
            }

            object             result     = null;
            string             sql        = null;
            List <DbParameter> parameters = null;
            TableEntity        ent        = null;

            FreshSQL(accessor, out sql, out parameters);
            var data = accessor.Retrieve(accessor.CreateCommand(sql, parameters));

            if (data != null && data.Rows.Count > 0)
            {
                result = CreateObject();
                switch (ForeignType)
                {
                case 1:     //Entity
                    ent = (TableEntity)result;
                    ent.SetDBAccessor(accessor);
                    ent.SetEntity(data.Rows[0]);
                    ent.Fresh();
                    break;

                case 2:     //List
                    foreach (DataRow row in data.Rows)
                    {
                        ent = CreateEntity();
                        ent.SetDBAccessor(accessor);
                        ent.SetEntity(row);
                        ent.Fresh();
                        AddEntity2List(ent, result);
                    }
                    break;
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        public List <IADbCommand> GetDeleteADbCommands(DatabaseCore accessor, Action <DbCommand, List <DbCommand> > action = null)
        {
            var commands = new List <IADbCommand>();

            if (accessor != null && Mode == ForeignMode.Correlative && Value != null)
            {
                switch (ForeignType)
                {
                case 1:     //Entity
                    commands.AddRange(((TableEntity)Value).INTERNAL_GetDeleteADbCommands(accessor));
                    break;

                case 2:     //List
                    string             sql        = string.Empty;
                    List <DbParameter> parameters = null;
                    DeleteSQL(accessor, out sql, out parameters);
                    var command = new ADbCommand(accessor.CreateCommand(sql, parameters), action);
                    commands.Add(command);
                    break;
                }
            }
            return(commands);
        }