- 优化 SqlServer WithIndex 使用习惯;

This commit is contained in:
2881099
2024-12-12 19:51:13 +08:00
parent cb10351821
commit af34ed845c

View File

@@ -119,7 +119,7 @@ public static partial class FreeSqlSqlServerGlobalExtensions
static TReturn LocalWithIndex<TReturn>(TReturn query, string indexName, Dictionary<Type, string> rule) static TReturn LocalWithIndex<TReturn>(TReturn query, string indexName, Dictionary<Type, string> rule)
{ {
if (string.IsNullOrWhiteSpace(indexName)) return query; if (string.IsNullOrWhiteSpace(indexName) && rule?.Any() != true) return query;
var selectProvider = query as Select0Provider; var selectProvider = query as Select0Provider;
switch (selectProvider._orm.Ado.DataType) switch (selectProvider._orm.Ado.DataType)
{ {
@@ -134,7 +134,7 @@ public static partial class FreeSqlSqlServerGlobalExtensions
selectProvider._aliasRule = (type, old) => selectProvider._aliasRule = (type, old) =>
{ {
if (oldalias != null) old = oldalias(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; if (rule == null) return old;
return rule.TryGetValue(type, out var tryidxName) && string.IsNullOrWhiteSpace(tryidxName) == false ? LocalAppendWithString(old, $"index={tryidxName}") : old; return rule.TryGetValue(type, out var tryidxName) && string.IsNullOrWhiteSpace(tryidxName) == false ? LocalAppendWithString(old, $"index={tryidxName}") : old;
}; };