private IList <DbKeyColumnInfo> ConstructDefaultOrderBy(DbTableInfo table) { var keyMembers = table.Entity.DefaultOrderBy; if (keyMembers == null || keyMembers.Count == 0) { return(null); } var orderByList = new List <DbKeyColumnInfo>(); var ent = table.Entity; foreach (var keyMember in keyMembers) { var col = table.Columns.FirstOrDefault(c => c.Member == keyMember.Member); if (col == null) { // This might happen in OrderBy on many-to-many list, when we order by member in target table // ex: Author.Books, order by book.PublishedOn; in this case primary table is link table IBookAuthor; // otherTbl is IBook var otherTbl = _dbModel.GetTable(keyMember.Member.Entity.EntityType); if (otherTbl != null) { col = otherTbl.Columns.FirstOrDefault(c => c.Member == keyMember.Member); } } if (col == null) { _log.LogError($"Failed to build ORDER BY list for table {table.TableName}: " + $"cannot find column for member {keyMember.Member.MemberName}."); } var dbKeyColumn = new DbKeyColumnInfo(col, keyMember); orderByList.Add(dbKeyColumn); } if (orderByList.Count == 0) { return(null); } return(orderByList); }
protected virtual string FormatOrderByEntry(DbKeyColumnInfo colInfo) { return colInfo.ToString(); }
private IList<DbKeyColumnInfo> ConstructOrderBy(DbTableInfo table) { var orderByList = new List<DbKeyColumnInfo>(); var ent = table.Entity; foreach (var keyMember in ent.DefaultOrderBy) { var col = table.Columns.FirstOrDefault(c=>c.Member == keyMember.Member); if (col == null) LogError("Failed to build ORDER BY list for table {0}: cannot find column for member {1}.", table.TableName, keyMember.Member.MemberName); var dbKeyColumn = new DbKeyColumnInfo(col, keyMember); orderByList.Add(dbKeyColumn); } if (orderByList.Count == 0) return null; return orderByList; }
protected override string FormatOrderByEntry(DbKeyColumnInfo colInfo) { return base.FormatOrderByEntry(colInfo) + " COLLATE NOCASE"; }