添加keylong的其他时区的支持发布x.4.1.7
This commit is contained in:
parent
13e3469a4f
commit
8ad08bc33f
|
@ -125,7 +125,7 @@ dbcontext `AbstractShardingDbContext`和`IShardingTableDbContext`如果你是普
|
||||||
### 第四步添加分表路由
|
### 第四步添加分表路由
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
|
路由构造函数支持依赖注入,依赖注入的对象生命周期必须是单例
|
||||||
public class OrderVirtualTableRoute:AbstractSimpleShardingMonthKeyDateTimeVirtualTableRoute<Order>
|
public class OrderVirtualTableRoute:AbstractSimpleShardingMonthKeyDateTimeVirtualTableRoute<Order>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
16
README.md
16
README.md
|
@ -128,9 +128,15 @@ sharding table(spilt table eg. order_202101,order_202102,order_202103......),u n
|
||||||
### Step 4:Create route that data(Order) query mapping table name
|
### Step 4:Create route that data(Order) query mapping table name
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
|
Route constructor support dependency injection,that's life time scope is `Singleton`
|
||||||
public class OrderVirtualTableRoute:AbstractSimpleShardingMonthKeyDateTimeVirtualTableRoute<Order>
|
public class OrderVirtualTableRoute:AbstractSimpleShardingMonthKeyDateTimeVirtualTableRoute<Order>
|
||||||
{
|
{
|
||||||
|
//private readonly IServiceProvider _serviceProvider;
|
||||||
|
|
||||||
|
//public OrderVirtualTableRoute(IServiceProvider serviceProvider)
|
||||||
|
//{
|
||||||
|
//_serviceProvider = serviceProvider;
|
||||||
|
//}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// fixed value don't use DateTime.Now because if if application restart this value where change
|
/// fixed value don't use DateTime.Now because if if application restart this value where change
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -187,6 +193,7 @@ u need modify `AddDefaultDataSource` method second param(connection string),don'
|
||||||
}).AddConfig(op =>
|
}).AddConfig(op =>
|
||||||
{
|
{
|
||||||
op.ConfigId = "c1";
|
op.ConfigId = "c1";
|
||||||
|
//use your data base connection string
|
||||||
op.AddDefaultDataSource(Guid.NewGuid().ToString("n"),
|
op.AddDefaultDataSource(Guid.NewGuid().ToString("n"),
|
||||||
"Data Source=localhost;Initial Catalog=EFCoreShardingTableDB;Integrated Security=True;");
|
"Data Source=localhost;Initial Catalog=EFCoreShardingTableDB;Integrated Security=True;");
|
||||||
}).EnsureConfig();
|
}).EnsureConfig();
|
||||||
|
@ -203,7 +210,7 @@ u need modify `AddDefaultDataSource` method second param(connection string),don'
|
||||||
// other configure....
|
// other configure....
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
then efcore support sharding,like sharding-jdbc in java,u can happy coding for efcore
|
then efcore support sharding table,like sharding-jdbc in java,u can happy coding for efcore
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
|
@ -219,6 +226,11 @@ public class ValuesController : Controller
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<IActionResult> Get()
|
public async Task<IActionResult> Get()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//_myDbContext.Add(order);
|
||||||
|
//_myDbContext.Udpate(order);
|
||||||
|
//_myDbContext.Remove(order);
|
||||||
|
//_myDbContext.SaveChanges();
|
||||||
var order = await _myDbContext.Set<Order>().FirstOrDefaultAsync(o => o.Id == "2");
|
var order = await _myDbContext.Set<Order>().FirstOrDefaultAsync(o => o.Id == "2");
|
||||||
return OK(order)
|
return OK(order)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
:start
|
:start
|
||||||
::定义版本
|
::定义版本
|
||||||
set EFCORE2=2.4.1.06
|
set EFCORE2=2.4.1.07
|
||||||
set EFCORE3=3.4.1.06
|
set EFCORE3=3.4.1.07
|
||||||
set EFCORE5=5.4.1.06
|
set EFCORE5=5.4.1.07
|
||||||
set EFCORE6=6.4.1.06
|
set EFCORE6=6.4.1.07
|
||||||
|
|
||||||
::删除所有bin与obj下的文件
|
::删除所有bin与obj下的文件
|
||||||
@echo off
|
@echo off
|
||||||
|
|
|
@ -34,14 +34,13 @@ namespace ShardingCore.Helpers
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static readonly DateTime UtcStartTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
|
||||||
public static DateTime ConvertLongToDateTime(long timeStamp)
|
public static DateTime ConvertLongToDateTime(long timeStamp)
|
||||||
{
|
{
|
||||||
return UtcStartTime.AddMilliseconds(timeStamp).AddHours(8);
|
return DateTimeOffset.FromUnixTimeMilliseconds(timeStamp).LocalDateTime; ;
|
||||||
}
|
}
|
||||||
public static long ConvertDateTimeToLong(DateTime time)
|
public static long ConvertDateTimeToLong(DateTime localDateTime)
|
||||||
{
|
{
|
||||||
return (long)(time.AddHours(-8) - UtcStartTime).TotalMilliseconds;
|
return new DateTimeOffset(localDateTime).ToUnixTimeMilliseconds(); ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in New Issue