我有一個包含值的列表A1,A2,A3,A4 ... A10 ...從數據庫獲取的值按此順序排列。但是,當使用linq時,訂單更改爲A1,A10,A2,A20,A3 .....即使沒有使用按默認排序的順序也是按升序排列。有什麼辦法可以禁用這個默認排序?在linq c中禁用默認排序#
public static string[] GetCompleteAutoCompleteItemsUsingDataTable(this DataTable AutoCompleteTable, string strPrefixText, int Count)
{
string AutoCompleteFieldName = AutoCompleteTable.Columns[1].Caption;
List<string> objlistMain = new List<string>();
if (!string.IsNullOrEmpty(strPrefixText))
{
strPrefixText = strPrefixText.ToLower().RemoveSpecialCharactersFromString();
objlistMain = (from dr in AutoCompleteTable.Select("[" + AutoCompleteFieldName + "] <> ''").AsEnumerable() where dr.Field<string>(AutoCompleteFieldName).ToLower().RemoveSpecialCharactersFromString().StartsWith(strPrefixText) select dr.Field<string>(AutoCompleteFieldName)).Take(Count).ToList<string>();
if (objlistMain.Count < Count && AutoCompleteTable.Rows.Count > objlistMain.Count)
{
List<string> objlist = (from dr in AutoCompleteTable.Select("[" + AutoCompleteFieldName + "] <> ''").AsEnumerable() where dr.Field<string>(AutoCompleteFieldName).ToLower().RemoveSpecialCharactersFromString().Contains(strPrefixText) && !objlistMain.Contains(dr.Field<string>(AutoCompleteFieldName)) select dr.Field<string>(AutoCompleteFieldName)).Take(Count - objlistMain.Count). ToList<string>();
foreach (string str in objlist)
{
objlistMain.Add(str);
}
}
}
else
{
objlistMain = (from dr in AutoCompleteTable.Select().AsEnumerable() select dr.Field<string>(AutoCompleteFieldName)).Take(Count).ToList<string>();
}
return objlistMain.Distinct().ToArray();
}
你想要什麼命令? –
我不希望它被排序 –
也許你所說的升序是插入順序? –