diff --git a/XCode/DataAccessLayer/DAL.cs b/XCode/DataAccessLayer/DAL.cs
index a56e3a98e..2c71e700d 100644
--- a/XCode/DataAccessLayer/DAL.cs
+++ b/XCode/DataAccessLayer/DAL.cs
@@ -86,7 +86,7 @@ public partial class DAL
public IAsyncDbSession AsyncSession => (Db as DbBase)!.CreateSessionForAsync();
private String? _mapTo;
- private readonly ICache _cache = new MemoryCache();
+ private static ICache _cache = new MemoryCache();
#endregion
#region 创建函数
@@ -634,7 +634,7 @@ public partial class DAL
///
/// 获取所有表名,带缓存,不区分大小写
///
- public ICollection TableNames => _cache.GetOrAdd("tableNames", k => new HashSet(GetTableNames(), StringComparer.OrdinalIgnoreCase), 60) ?? [];
+ public ICollection TableNames => _cache.GetOrAdd($"tableNames:{ConnName}", k => new HashSet(GetTableNames(), StringComparer.OrdinalIgnoreCase), 60) ?? [];
///
/// 快速获取所有表名,无缓存,区分大小写
@@ -680,7 +680,7 @@ public partial class DAL
///
public static IList Import(String xml)
{
- if (xml.IsNullOrEmpty()) return new IDataTable[0];
+ if (xml.IsNullOrEmpty()) return [];
return ModelHelper.FromXml(xml, CreateTable);
}
@@ -820,6 +820,10 @@ public partial class DAL
span?.SetError(ex, null);
throw;
}
+ finally
+ {
+ _cache.Remove($"tableNames:{ConnName}");
+ }
}
private void FixIndexName(IDataTable table)
diff --git a/XUnitTest.XCode/EntityTests/TimeShardTests.cs b/XUnitTest.XCode/EntityTests/TimeShardTests.cs
new file mode 100644
index 000000000..0dafcfe85
--- /dev/null
+++ b/XUnitTest.XCode/EntityTests/TimeShardTests.cs
@@ -0,0 +1,44 @@
+using System;
+using System.IO;
+using NewLife;
+using XCode.Exceptions;
+using Xunit;
+using XUnitTest.XCode.TestEntity;
+
+namespace XUnitTest.XCode.EntityTests;
+
+public class TimeShardTests
+{
+ [Fact]
+ public void Test1()
+ {
+ var file = Setting.Current.DataPath.CombinePath("test.db");
+ if (File.Exists(file)) File.Delete(file);
+
+ //var dal = ExpressLogs.Meta.Session.Dal;
+ //var table = ExpressLogs.Meta.Table.DataTable;
+
+ //dal.SetTables(table);
+
+ // 对分表查行数,报错
+ Assert.Throws(() => ExpressLogs.FindCount());
+
+ // 分表查询,没有数据
+ var time = DateTime.Now.AddHours(1);
+ var list = ExpressLogs.Search(time.Date, time, null, null);
+ Assert.Empty(list);
+
+ // 写入数据
+ var entity = new ExpressLogs
+ {
+ Code = "123456",
+ };
+ entity.Insert();
+
+ list = ExpressLogs.Search(time.Date, time, null, null);
+ Assert.Single(list);
+
+ //var n = ExpressLogs.Meta.Count;
+ //Assert.Equal(0, n);
+ }
+}
diff --git a/XUnitTest.XCode/TimeShardTests.cs b/XUnitTest.XCode/TimeShardTests.cs
deleted file mode 100644
index 3ca4e8816..000000000
--- a/XUnitTest.XCode/TimeShardTests.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-using Xunit;
-
-using XUnitTest.XCode.TestEntity;
-
-namespace XUnitTest.XCode;
-
-public class TimeShardTests
-{
- [Fact]
- public void Test1()
- {
- var n = ExpressLogs.Meta.Count;
-
- Assert.Equal(0, n);
- }
-}