diff --git a/server/AyaNova/DataList/DataListSqlSelectBuilder.cs b/server/AyaNova/DataList/DataListSqlSelectBuilder.cs index cd612d91..af6fe330 100644 --- a/server/AyaNova/DataList/DataListSqlSelectBuilder.cs +++ b/server/AyaNova/DataList/DataListSqlSelectBuilder.cs @@ -134,35 +134,80 @@ namespace AyaNova.DataList #endif if (o != null && o.IsRowId)//only return the rowid column {//Ignore missing fields in production - - var valueColumnName = o.GetSqlValueColumnName(); - if (!map.ContainsKey(valueColumnName)) - { - if (firstColumnAdded) - sb.Append(", "); - sb.Append(valueColumnName); - firstColumnAdded = true; - map.Add(valueColumnName, nOrdinal++); - } - - //does it also have an ID column? - var idColumnName = o.SqlIdColumnName; - if (!string.IsNullOrWhiteSpace(idColumnName)) - { - if (!map.ContainsKey(idColumnName)) - { - if (firstColumnAdded) - sb.Append(", "); - sb.Append(idColumnName); - firstColumnAdded = true; - map.Add(idColumnName, nOrdinal++); - } - } + AddTheColumn(sb, map, ref nOrdinal, ref firstColumnAdded, o); } } + + + //insert rowid if it wasn't specified already in the list view + //this is legit as some datalists don't have a rowid visible to user e.g. PartInventoryOnHand + if (map.Count == 0) + { + //find the rowid in the objectfields list and insert it since it wasn't in the view already + var o = objectFieldsList.FirstOrDefault(z => z.IsRowId == true); + if (o != null) + { + // if(!string.IsNullOrWhiteSpace(rowIdColumn.SqlIdColumnName)){ + // map.Add(rowIdColumn.SqlIdColumnName, nOrdinal++); + // }else{ + // map.Add(rowIdColumn.GetSqlValueColumnName(), nOrdinal++); + // } + AddTheColumn(sb, map, ref nOrdinal, ref firstColumnAdded, o); + } + + } return new SqlSelectBuilderResult() { map = map, Select = sb.ToString() }; }//eof + private static void AddTheColumn(StringBuilder sb, Dictionary map, ref int nOrdinal, ref bool firstColumnAdded, AyaDataListFieldDefinition o) + { + // var valueColumnName = o.GetSqlValueColumnName(); + // if (!map.ContainsKey(valueColumnName)) + // { + // if (firstColumnAdded) + // sb.Append(", "); + // sb.Append(valueColumnName); + // firstColumnAdded = true; + // map.Add(valueColumnName, nOrdinal++); + // } + // //does it also have an ID column? + // var idColumnName = o.SqlIdColumnName; + // if (!string.IsNullOrWhiteSpace(idColumnName)) + // { + // if (!map.ContainsKey(idColumnName)) + // { + // if (firstColumnAdded) + // sb.Append(", "); + // sb.Append(idColumnName); + // firstColumnAdded = true; + // map.Add(idColumnName, nOrdinal++); + // } + // } + + // var valueColumnName = o.GetSqlValueColumnName(); + // if (!map.ContainsKey(valueColumnName)) + // { + // if (firstColumnAdded) + // sb.Append(", "); + // sb.Append(valueColumnName); + // firstColumnAdded = true; + // map.Add(valueColumnName, nOrdinal++); + // } + + //does it also have an ID column? + var idColumnName = o.SqlIdColumnName; + if (!string.IsNullOrWhiteSpace(idColumnName)) + { + // if (!map.ContainsKey(idColumnName)) + // { + // if (firstColumnAdded) + // sb.Append(", "); + sb.Append(idColumnName); + // firstColumnAdded = true; + map.Add(idColumnName, 0); + // } + } + } }//eoc }//ens