I am trying to convert the ffg:,
This Works
IResultSEt rs = db.SELECT.COLUMNS(db.GetTable(data.ToString()).ColumnNames).FROM(data.ToString()).Execute();
into this, which does not work,
dynamic rs = db.SELECT.COLUMNS(db.GetTable(data.ToString()).ColumnNames);
rs = rs.FROM(data.ToString());
rs = rs.Execute();
It gives me an error that it cannot find "COLUMNS".
While debugging, it seems that rs is picking up all the return methods and private variables in the SELECT class it just is not picking up the method like COLUMNS in the SELECT class at runtime. This is very odd, I expected it to also pick up the methods, I am doing something wrong???
UPDATE
The definition for db in db.SELECT.COLUMNS(db.GetTable(data.ToString()).ColumnNames); is
public class Database
{
private Dictionary<string, ITable> _tables = new Dictionary<string, ITable>();
public ITable AddTable(string tableName, string[]columnNames, Type[] columnTypes)
{
ITable tbl = new Table(tableName);
tbl.SetColumns(columnNames, columnTypes);
_tables.Add(tableName.ToUpper(), tbl);
return tbl;
}
public ITable GetTable(string tableName)
{
return _tables[tableName.ToUpper()];
}
public ISELECT SELECT
{
get
{
ISELECT select = new SELECT(this);
return select;
}
}
public Dictionary<string,ITable> getTables()
{
return _tables;
}
}
The definition for SELECT in db.SELECT.COLUMNS(db.GetTable(data.ToString()).ColumnNames); which is an interface to my SELECT class;
public interface ISELECT
{
ISELECT TOP(Int32 N);
ISELECT DISTINCT { get; }
ISELECTCOLUMN COLUMN(string columnName);
ISELECTTABLECOLUMN COLUMN(string tableName, string columnName);
ISELECTCOLUMNS COLUMNS(params string[] columnNames);
ISELECTSUMCOLUMN SUM(string columnName);
ISELECTSUMCOLUMN SUM(string tableName, string columnName);
}
This is where the problem lies, the dynamic object is not picking up the methods in the interface, it picks up all private variables and the only method it picks up is "DISTINCT".
Below is part of the definition of the SELECT class, there is alot of code in it so I will just put a little;
internal class SELECT : ISELECT, ISELECTInternals
{
private Database _dw;
private bool _DISTINCT;
private Int32 _TOPN = -1;
private List<Int32> _JOINNumbers = new List<Int32>();
private string[] _selectJOINLHScolumnTableNames;
private string[] _selectJOINLHScolumnNames;
private string[] _selectJOINRHScolumnTableNames;
private string[] _selectJOINRHScolumnNames;
private string[] _selectcolumnTableNames;
private string[] _selectcolumnNames;
private string[] _selectcolumnAliases;
private object[] _selectcolumnLiterals;
private string[] _selectcolumnStringTemplates;
private AggregateTypes[] _selectcolumnAggregates;
private string[] _queryTableNames;
private string _SUMcolumnName;
private string _FROMTableName;
private List<string> _INNERJOINTableNames = new List<string>();
private List<string> _JOINTableNames = new List<string>();
private List<JoinTypes> _TableJoinTypes = new List<JoinTypes>();
private bool _takeANDFlag = true;
private List<string> _filterColumnTableNames = new List<string>();
private List<string> _filterColumnNames = new List<string>();
private List<object[]> _filterColumnValues = new List<object[]>();
private List<string> _GROUPBYcolumnTableNames = new List<string>();
private List<string> _GROUPBYcolumnNames = new List<string>();
etc.
Something else has to have changed. Altering where or if a particular expression is captured does not cause it to throw an exception before it stores the value/reference.
Perhaps using statements or other types have changed and you didn't realize that between the success of the line
IResultSEt rs = db.SELECT.COLUMNS(db.GetTable(data.ToString()).ColumnNames)
and the failure of the line
dynamic rs = db.SELECT.COLUMNS(db.GetTable(data.ToString()).ColumnNames);
but it failing on locating a method on db means that either the type of db has changed or the usings that would import extension methods have changed.
Let me try to restate. The left side of the storage has NO effect on how the right side is evaluated until the entire right side is done evaluating. (not accounting for the left side saying Expression<Func<>>
vs. Func<>
)
I think more has changed since you put the question together that wasn't accounted for in the question or the source code posted in the question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With