This commit is contained in:
sunkaixuan 2023-10-24 18:06:15 +08:00
parent 28f9b36992
commit b1a758fe61
2 changed files with 44 additions and 1 deletions

View File

@ -0,0 +1,23 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CacheTest
{
public class Order
{
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
[SugarColumn(IsNullable = true)]
public DateTime CreateTime { get; set; }
[SugarColumn(IsNullable =true)]
public int CustomId { get; set; }
}
}

View File

@ -1,4 +1,5 @@
using System; using SqlSugar;
using System;
namespace CacheTest namespace CacheTest
{ {
@ -17,6 +18,25 @@ namespace CacheTest
var testr=cache.GetOrCreate<string>("a33",()=> { return "aaa"; },10); var testr=cache.GetOrCreate<string>("a33",()=> { return "aaa"; },10);
cache.Remove<string>("aaaaaaaa"); cache.Remove<string>("aaaaaaaa");
cache.Remove<string>("a"); cache.Remove<string>("a");
ICacheService myCache = cache;
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = "server=.;uid=sa;pwd=sasa;database=SQLSUGAR4XTEST",
DbType = DbType.SqlServer,
IsAutoCloseConnection = true,
MoreSettings=new ConnMoreSettings() {
IsAutoRemoveDataCache = true,
},
ConfigureExternalServices = new ConfigureExternalServices()
{
DataInfoCacheService = myCache //配置我们创建的缓存类具体用法看标题5
}
});
db.Fastest<Order>().BulkCopy(new System.Collections.Generic.List<Order>()
{
new Order(){ CreateTime=DateTime.Now, CustomId=1, Name="a" }
});
Console.WriteLine("Hello World!"); Console.WriteLine("Hello World!");
} }
} }