SqlSugar ORM has separate read and write support

Currently only supports MYSQL version 3.5.2.9, its library version December 3 update this feature

 

Use cases to explain 

Copy the code
using (var db = new SqlSugarClient ( " primary connection string", "from the connection string" "can be connected to a plurality of slave")) 
{ 
  var = db.Queryable List <Student> () ToList ();. // away from the 
  var list = db.Queryable <Student> ( ) toJson ();. // away from the 
  db.Insert (new Student () {name = " write"}); // take the main 
  db.Delete (new Student () {id = 1}) ; // go main 
  db.BeginTran // operations are the primary transaction 
   
   
}
Copy the code

 

Explanation

Copy the code
/// <Summary> 

/// new instance (master-slave mode) class initialization SqlSugarClient 
/// </ Summary> 
/// <param name = "masterConnectionString"> Main: write transactions and other operations </ param> 
/ // <param name = "slaveConnectionString" > from: no transaction reads </ param> 
public SqlSugarClient (String masterConnectionString, the params String [] slaveConnectionString) 
    : Base (masterConnectionString, slaveConnectionString) 
{ 
    the ConnectionString = masterConnectionString; 
}
Copy the code

 

note:

 

ORM is the perfect support for the separation of master and slave, but you also need to set up your database before they can open the main synchronization from, for example, SqlServer have alwayson technology.

 

If you do not know SqlSugar ORM Please check  http://www.codeisbug.com/Home/Doc?typeId=7

Guess you like

Origin www.cnblogs.com/Jeely/p/11357155.html