In the previous version we can implement the constructor, in fact, the current version is the same, before the construction of the connection string, now similar, constructs dbcontextoptions<t>
The code is as follows:
PublicScontext (Masterslave masterslave):Base(GetOptions (Masterslave)) {//TODO: #639//changetracker.querytrackingbehavior = querytrackingbehavior.notracking; } /// <summary> ///master-Slave relationship/// </summary> /// <param name= "Writeread" ></param> /// <returns></returns> Private StaticDbcontextoptions<scontext>getoptions (Masterslave masterslave) {varOptionsbuilder =NewDbcontextoptionsbuilder<scontext>(); if(Masterslave = =masterslave.slave) {optionsbuilder.usesqlserver (Config.DbConfig.Read); } Else{optionsbuilder.usesqlserver (Config.DbConfig.Write); } returnoptionsbuilder.options; }
Entity Framework Core for read-write separation