This commit is contained in:
2020-02-15 00:17:09 +00:00
parent 2319c22745
commit 0b5d548d91
4 changed files with 74 additions and 19 deletions

View File

@@ -37,7 +37,15 @@ namespace AyaNova.DataList
sb.Append(" AS df");
bool CustomFieldIncluded = false;
//keep track of which custom fields columns were added already
//this ensures that if there is more than one set of custom fields like from two different objects in the list
//only unique ones will be returned by query
// Dictionary<string, int> CustomFieldColumnsAddedToQuery = new Dictionary<string, int>();
//map sql column name to ordinal name
Dictionary<string, int> map = new Dictionary<string, int>();
map.Add("df", 0);
int nOrdinal = 0;
foreach (string ColumnName in listViewFieldList)
{
//skip the df column, it's already been processed above
@@ -54,29 +62,42 @@ namespace AyaNova.DataList
if (o != null)
{//Ignore missing fields in production
if (o.IsCustomField && !CustomFieldIncluded)
if (o.IsCustomField)
{ //if any are custom field then add custom fields column to query
CustomFieldIncluded=true;
sb.Append(", ");
sb.Append(o.GetSqlValueColumnName());
var CustomFieldSqlColumnName = o.GetSqlValueColumnName();
//has it been added yet?
if (!map.ContainsKey(CustomFieldSqlColumnName))
{ //nope
sb.Append(", ");
sb.Append(CustomFieldSqlColumnName);
map.Add(CustomFieldSqlColumnName, ++nOrdinal);
}
//if it was already added then can just ignore it
// else
// {
// map.Add(ColumnName, CustomFieldColumnsAddedToQuery[CustomFieldSqlColumnName]);
// }
}
else
{
sb.Append(", ");
sb.Append(o.GetSqlValueColumnName());
map.Add(o.GetSqlValueColumnName(), ++nOrdinal);
//does it also have an ID column?
if (!string.IsNullOrWhiteSpace(o.SqlIdColumnName))
{
sb.Append(", ");
sb.Append(o.SqlIdColumnName);
map.Add(o.SqlIdColumnName, ++nOrdinal);
}
}
}
}
TODO: return map and sb as composite object here
return sb.ToString();
}