Ejemplo n.º 1
0
 public int DeleteAll()
 {
     using (var context = new GreenWerxDbContext(_dbConnectionKey))
     {
         string table = DatabaseEx.GetTableName <LogEntry>();
         return(context.ExecuteNonQuery("DELETE FROM " + table, null));
     }
 }
Ejemplo n.º 2
0
        protected DataQuery BuildQuery(string typeName, List <DataScreen> screens)
        {
            DataQuery dq = new DataQuery();

            string table = DatabaseEx.GetTableName(typeName);

            if (string.IsNullOrEmpty(table))
            {
                dq.SQL = "ERROR: Table name could not be found.";
                return(dq);
            }

            //Set default sql query
            dq.SQL        = "SELECT * FROM " + table;
            dq.Parameters = null;

            if (screens == null || screens.Count == 0)
            {
                return(dq);
            }

            //Check if we do a distinct query.
            //
            DataScreen distinctDataScreen = screens.FirstOrDefault(w => w.Command?.ToLower() == "distinct");

            if (distinctDataScreen == null)
            {
                dq.SQL += GetWhereClause(screens);
            }
            else
            {
                dq.SQL = "SELECT DISTINCT( " + distinctDataScreen.Field + " ) FROM " + table + GetWhereClause(screens);
            }

            return(dq);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// returns a query based on the screens
        /// Not using parameters. kept throwing “Invalid type owner for DynamicMethod” error
        /// </summary>
        /// <param name="screens"></param>
        /// <returns></returns>
        protected DataQuery BuildQuery <T>(List <DataScreen> screens) where T : class
        {
            DataQuery dq    = new DataQuery();
            string    table = DatabaseEx.GetTableName <T>();

            if (string.IsNullOrEmpty(table))
            {
                dq.SQL = "ERROR: Table name could not be parsed.";
                return(dq);
            }

            dq.SQL = "SELECT * FROM " + table;

            if (screens.Count() == 0)
            {
                return(dq);
            }

            dq.SQL += GetWhereClause(screens);

            dq.Parameters = null;

            return(dq);
        }