diff --git a/Providers/FreeSql.Provider.SqlServer/SqlServerExtensions.cs b/Providers/FreeSql.Provider.SqlServer/SqlServerExtensions.cs index 5dc4a8560..646f8a6ff 100644 --- a/Providers/FreeSql.Provider.SqlServer/SqlServerExtensions.cs +++ b/Providers/FreeSql.Provider.SqlServer/SqlServerExtensions.cs @@ -119,7 +119,7 @@ static TReturn LocalWithLock(TReturn query, SqlServerLock lockType, Dic static TReturn LocalWithIndex(TReturn query, string indexName, Dictionary rule) { - if (string.IsNullOrWhiteSpace(indexName)) return query; + if (string.IsNullOrWhiteSpace(indexName) && rule?.Any() != true) return query; var selectProvider = query as Select0Provider; switch (selectProvider._orm.Ado.DataType) { @@ -134,7 +134,7 @@ static TReturn LocalWithIndex(TReturn query, string indexName, Dictiona selectProvider._aliasRule = (type, old) => { if (oldalias != null) old = oldalias(type, old); - if (type == selectProvider._tables[0].Table.Type) return LocalAppendWithString(old, $"index={indexName}"); + if (string.IsNullOrWhiteSpace(indexName) == false && type == selectProvider._tables[0].Table.Type) return LocalAppendWithString(old, $"index={indexName}"); if (rule == null) return old; return rule.TryGetValue(type, out var tryidxName) && string.IsNullOrWhiteSpace(tryidxName) == false ? LocalAppendWithString(old, $"index={tryidxName}") : old; };