The A2D framework adds EF support, plus the original support ado.net:
Support EF Mode
Support Ado.net Mode
This time, how to make the Entity Framework into NB of read and write separation
1. First design EF model, can be graphic design, can also be database priority design, in short, after design, and then converted to the code way to use (with)
2. In the DbContext class, delete the error code that the EF automatically adds, as follows:
protected override void Onmodelcreating (Dbmodelbuilder modelbuilder)
{
throw new Unintentionalcodefirstexception ()//delete this sentence directly
3. Add a2d profile a2d.config in the root directory:
<?xml version= "1.0" encoding= "Utf-8"?>
<A2D>
<SQLDispatcher>
<WritableDB> server=192.168.1.20; User Id=sa; PASSWORD=111111;DATABASE=DFH; Connection reset=false</writabledb>
<ReadDBs>
<DB>server=192.168.1.21; User Id=sa; PASSWORD=111111;DATABASE=DFH; Connection reset=false</db>
<DB>server=192.168.1.22; User Id=sa; PASSWORD=111111;DATABASE=DFH; Connection reset=false</db>
</ReadDBs>
</SQLDispatcher>
</A2D>
4. Write query interface, query Impl
Interface Iorder
{
[sqldispatcher]
list<order> queryorders (string keyword);
}
[Aopserviceenabled]
Class Orderimpl:contextboundobject, Iorder
{
private irepository repository = objectfactory.resolve< Irepository> ();
Public list<order> queryorders (string keyword)
{
list<order> orders=repository. Get<order> (filter:w =>
w.firstname.indexof (keyword) >=0);
return orders;
}