Read and write separation subsystem

Source: Internet
Author: User
Tags error code reset connection reset root directory

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;
        }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.