FreeSql (thirty) separate read and write

FreeSql support database read and write separation, this function is to separate read and write behavior of the client, how to configure the database server is still configured as not affected by this function, in order to facilitate the later description technique mentioned [separation] refer clients to read and write end feature support.

Various programs read and write different database, the database is enabled with separate read and write functions, separate read and write to achieve roughly divided into the following:

1, nginx agent, tedious and error-prone configuration;

2, the inter-member, such as myCat;

3, the client-side support;

FreeSql achieved the first three kinds of programs to support a [more] main library from the library [], [] query strategy from the library of random way.

If a [] from the library fails to switch to another available [] from the library, all unavailable Ruoyi the primary library using {} query.

Failure [] are isolated from a library of intermittently check the available state to be restored.

var connstr = "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;" + 
    "Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=10";

IFreeSql fsql = new FreeSql.FreeSqlBuilder()
    .UseConnectionString(FreeSql.DataType.MySql, connstr)
    .UseSlave("connectionString1", "connectionString2") //使用从数据库,支持多个
    .Build();

select.Where(a => a.Id == 1).ToOne(); //读【从库】(默认)
select.Master().WhereId(a => a.Id == 1).ToOne(); //强制读【主库】

Guess you like

Origin www.cnblogs.com/FreeSql/p/11531430.html