添加捐赠和部分使用代码
This commit is contained in:
parent
022e063dad
commit
683aef8549
|
@ -12,6 +12,7 @@
|
|||
---
|
||||
- [Gitee](https://gitee.com/dotnetchina/sharding-core) 国内镜像
|
||||
|
||||
- [捐赠](#捐赠)
|
||||
|
||||
## 社区合作伙伴和赞助商
|
||||
|
||||
|
@ -1085,6 +1086,10 @@ return optionsBuilder.ReplaceService<IModelCacheKeyFactory, ShardingModelCacheKe
|
|||
|
||||
凭借各大开源生态圈提供的优秀代码和思路才有的这个框架,希望可以为.Net生态提供一份微薄之力,该框架本人会一直长期维护,有大神技术支持可以联系下方方式欢迎star :)
|
||||
|
||||
# 捐赠
|
||||
<img src="./imgs/zfb.jpg" title="JetBrains" width=200 />
|
||||
<img src="./imgs/wx.jpg" title="JetBrains" width=222 />
|
||||
|
||||
[博客](https://www.cnblogs.com/xuejiaming)
|
||||
|
||||
QQ群:771630778
|
||||
|
|
|
@ -13,6 +13,7 @@ high performance lightweight solution for efcore sharding table and sharding dat
|
|||
---
|
||||
- [Gitee](https://gitee.com/dotnetchina/sharding-core) 国内镜像
|
||||
|
||||
- [捐赠](#捐赠)
|
||||
|
||||
## Community Partners and Sponsors
|
||||
|
||||
|
@ -1101,6 +1102,9 @@ return optionsBuilder.ReplaceService<IModelCacheKeyFactory, ShardingModelCacheKe
|
|||
|
||||
凭借各大开源生态圈提供的优秀代码和思路才有的这个框架,希望可以为.Net生态提供一份微薄之力,该框架本人会一直长期维护,有大神技术支持可以联系下方方式欢迎star :)
|
||||
|
||||
# 捐赠
|
||||
<img src="./imgs/zfb.jpg" title="JetBrains" width=200 />
|
||||
<img src="./imgs/wx.jpg" title="JetBrains" width=222 />
|
||||
[博客](https://www.cnblogs.com/xuejiaming)
|
||||
|
||||
QQ群:771630778
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 63 KiB |
Binary file not shown.
After Width: | Height: | Size: 121 KiB |
|
@ -0,0 +1,31 @@
|
|||
using System.Linq.Expressions;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Internal;
|
||||
using Microsoft.EntityFrameworkCore.Query;
|
||||
using ShardingCore.Extensions;
|
||||
|
||||
namespace Sample.MySql.Controllers;
|
||||
|
||||
public class DbSetDiscoverExpressionVisitor<TEntity>:ExpressionVisitor where TEntity:class
|
||||
{
|
||||
private readonly DbContext _dbContext;
|
||||
public DbSet<TEntity> DbSet { get; private set; }
|
||||
|
||||
public DbSetDiscoverExpressionVisitor(DbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
protected override Expression VisitExtension(Expression node)
|
||||
{
|
||||
if (node is QueryRootExpression queryRootExpression)
|
||||
{
|
||||
var dbContextDependencies =
|
||||
typeof(DbContext).GetTypePropertyValue(_dbContext, "DbContextDependencies") as IDbContextDependencies;
|
||||
var targetIQ =
|
||||
((IDbSetCache)_dbContext).GetOrAddSet(dbContextDependencies.SetSource, queryRootExpression.EntityType.ClrType);
|
||||
DbSet = (DbSet<TEntity>)targetIQ;
|
||||
}
|
||||
return base.VisitExtension(node);
|
||||
}
|
||||
}
|
|
@ -32,6 +32,18 @@ namespace Sample.MySql.Controllers
|
|||
[HttpGet]
|
||||
public async Task<IActionResult> Get()
|
||||
{
|
||||
OtherDbContext.CurrentId = "";
|
||||
var myUsers0 = _otherDbContext.MyUsers.ToList();
|
||||
OtherDbContext.CurrentId = "123";
|
||||
var myUsers1 = _otherDbContext.MyUsers.ToList();
|
||||
OtherDbContext.CurrentId = "456";
|
||||
var myUsers2= _otherDbContext.MyUsers.ToList();
|
||||
|
||||
// var sysUserModQueryable = _otherDbContext.MyUsers.Where(o => o.Id == "2");
|
||||
// var dbSetDiscoverExpressionVisitor = new DbSetDiscoverExpressionVisitor<MyUser>(_otherDbContext);
|
||||
// dbSetDiscoverExpressionVisitor.Visit(sysUserModQueryable.Expression);
|
||||
// var myUsers = dbSetDiscoverExpressionVisitor.DbSet;
|
||||
// Console.WriteLine("------------");
|
||||
// using (var tran = _defaultTableDbContext.Database.BeginTransaction())
|
||||
// {
|
||||
|
||||
|
|
|
@ -74,6 +74,7 @@ namespace Sample.MySql
|
|||
{
|
||||
builder.UseMySql(conStr, new MySqlServerVersion(new Version()))
|
||||
.UseLoggerFactory(efLogger)
|
||||
.EnableSensitiveDataLogging()
|
||||
.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
|
||||
});
|
||||
o.UseShardingTransaction((connection, builder) =>
|
||||
|
@ -81,6 +82,7 @@ namespace Sample.MySql
|
|||
builder
|
||||
.UseMySql(connection, new MySqlServerVersion(new Version()))
|
||||
.UseLoggerFactory(efLogger)
|
||||
.EnableSensitiveDataLogging()
|
||||
.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
|
||||
});
|
||||
o.UseShardingMigrationConfigure(b =>
|
||||
|
@ -107,6 +109,7 @@ namespace Sample.MySql
|
|||
{
|
||||
builder.UseMySql(conStr, new MySqlServerVersion(new Version()))
|
||||
.UseLoggerFactory(efLogger)
|
||||
.EnableSensitiveDataLogging()
|
||||
.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
|
||||
});
|
||||
o.UseShardingTransaction((connection, builder) =>
|
||||
|
@ -114,6 +117,7 @@ namespace Sample.MySql
|
|||
builder
|
||||
.UseMySql(connection, new MySqlServerVersion(new Version()))
|
||||
.UseLoggerFactory(efLogger)
|
||||
.EnableSensitiveDataLogging()
|
||||
.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
|
||||
});
|
||||
o.AddDefaultDataSource("ds0",
|
||||
|
@ -123,20 +127,6 @@ namespace Sample.MySql
|
|||
{ "ds1", "server=127.0.0.1;port=3306;database=dbdbd1;userid=root;password=root;" },
|
||||
{ "ds2", "server=127.0.0.1;port=3306;database=dbdbd2;userid=root;password=root;" }
|
||||
});
|
||||
// o.AddReadWriteSeparation(sp =>
|
||||
// {
|
||||
// return new Dictionary<string, IEnumerable<string>>()
|
||||
// {
|
||||
// {
|
||||
// "ds0",
|
||||
// new[]
|
||||
// {
|
||||
// "server=127.0.0.1;port=3306;database=dbdbd0_0;userid=root;password=root;"
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
// }, defaultEnable: true, readStrategyEnum: ReadStrategyEnum.Loop,
|
||||
// readConnStringGetStrategy: ReadConnStringGetStrategyEnum.LatestEveryTime);
|
||||
o.UseShardingMigrationConfigure(b =>
|
||||
{
|
||||
b.ReplaceService<IMigrationsSqlGenerator, ShardingMySqlMigrationsSqlGenerator>();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Debug",
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
|
|
|
@ -12,5 +12,15 @@ public class OtherDbContext:AbstractShardingDbContext,IShardingTableDbContext
|
|||
{
|
||||
}
|
||||
|
||||
public static string CurrentId;
|
||||
public string CID => CurrentId;
|
||||
public bool HasCID => !string.IsNullOrWhiteSpace(CID);
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
modelBuilder.Entity<MyUser>()
|
||||
.HasQueryFilter(o => !HasCID || o.Id == CID);
|
||||
}
|
||||
|
||||
public IRouteTail RouteTail { get; set; }
|
||||
}
|
Loading…
Reference in New Issue