An open source project for EF Core lightweight sub-table sub-library, read-write separation

For more open source projects, please check: A list focusing on recommending .Net open source projects

In project development, if the amount of data is relatively large, such as log records, we often adopt the scheme of sub-table and sub-database; in order to improve performance, the database query and update operations are separated, and the read-write separation scheme is adopted at this time.

Table sub-database usually includes vertical sub-database, vertical table sub-database, horizontal sub-database and horizontal table sub-database scheme, including sub-table sub-database scheme. It takes a certain amount of time to implement each scheme; therefore, today I recommend an EF- based Code realizes sub-table and sub-library, and read-write separation open source library, which allows us to access at zero cost.

Project Description

This is an open source project aimed at EF Code's high performance, lightweight sub-table and sub-library, and read-write separation. It allows us to access quickly and easily, or transform the original project, and access it at almost zero cost.

project characteristics

1. Sub-table: time sub-table, custom sub-table, multi-table query update and delete.

2. Sub-database: support custom sub-database, sub-database query, update and delete.

3. Sub-table and sub-database: support partial table sub-table and partial table sub-database.

4. Separation of reading and writing: supports the scheme of separating reading and writing from one master to multiple slaves.

5. Others: Support dynamic table and database subdivision, support high-performance query, support transactions, etc.

Technology Architecture

1. Cross-platform: Based on .NetCore development, it supports Windows, Mono, Liunx, and Windows Azure.

2. Support Standard 2.0, .NetCore 2.0+.

3. Database: Support MySql, Oracle, SqlServer.

project structure

picture

The project contains examples of different databases, and src is the source code of different versions.

Get started quickly

**1. Table definition
**

public class SysUserMod:IAge
{
/// <summary>
/// 用户Id用于分表
/// </summary>
public string Id { get; set; }
/// <summary>
/// 用户名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 用户姓名
/// </summary>
public int Age { get; set; }
}

2. Sub-table rules

public class SysUserModVirtualTableRoute : AbstractSimpleShardingModKeyStringVirtualTableRoute<SysUserMod>
{
    //根据ID取模3,分为2张表
public SysUserModVirtualTableRoute() : base(2,3)
    {
    }

public override void Configure(EntityMetadataTableBuilder<SysUserMod> builder)
    {
        builder.ShardingProperty(o => o.Id);
    }

}

3. Startup configuration

public void ConfigureServices(IServiceCollection services)
{
    ......
    services.AddShardingDbContext<DefaultShardingDbContext>()
        .UseRouteConfig(o =>
        {
//定义分表路由
            o.AddShardingDataSourceRoute<SysUserModVirtualDataSourceRoute>();
        }).UseConfig((sp,o) =>
        {
            ......
//指定主从数据库
            o.AddDefaultDataSource("ds0",
"server=127.0.0.1;port=3306;database=db1;userid=root;password=root;");
            o.AddExtraDataSource(sp => new Dictionary<string, string>()
            {
                { "ds1", "server=127.0.0.1;port=3306;database=db2;userid=root;password=root;" },
                { "ds2", "server=127.0.0.1;port=3306;database=db3;userid=root;password=root;" }
            });
            o.UseShardingMigrationConfigure(b =>
            {
                b.ReplaceService<IMigrationsSqlGenerator, ShardingMySqlMigrationsSqlGenerator>();
            });
        }).ReplaceService<IModelCacheLockerProvider,DicModelCacheLockerProvider>()
        .AddShardingCore();
}

project address

Github:

https://github.com/dotnetcore/sharding-core

Gitee:

https://gitee.com/xuejm/sharding-core

- End -

Welcome to join the learning circle , get massive programming learning resources and learning routes, check in with everyone, share programming knowledge, and make progress together.

recommended reading

A simple, fully functional WMS warehouse management system

The method and experience of reading the source code of open source projects

A Socket extension library developed based on C#

The payment SDK developed based on .Net Core simplifies the development of payment functions

Annual inventory of 10 most popular .Net open source projects

Guess you like

Origin blog.csdn.net/daremeself/article/details/128995614