Mygeneration Study Notes (10): Configure database connections

Source: Internet
Author: User

In my mygeneration Study Notes (1): Use mygeneration to generate stored procedures and data access layer code, I mentioned using internal string _ raw = projectname. properties. settings. default. connectionstring; this statement is used to initialize the database connection string. Now, you can only use this method in a single database system.ProgramIf the set (assembly) requires multiple databases, you need to find another method :)

One method is the original method I mentioned at the beginning: "manually assign a value to the connectionstring attribute in the application, but in this case, assign a value to the connectionstring value after each business entity completes the new operation ". It seems that this method is not great. Imagine that when building an application with a n-layer architecture, the developers at the upper layer of the concrete class also need to know which database the concrete class currently operates on, which table in the corresponding database is depressing...

Can I encapsulate database connection operations? The answer is yes! Solution: Set the database connection string in the concrete class constructor generated by doodad. For example:
public class employee: _ employee
{< br> public employee ()
{< br> This. connectionstring = properties. settings. default. strconnectto * dB;
}< br> // other members
}< br> in this way, the developers at the upper layer of the concrete class do not have to worry about the databases at the bottom layer and the databases to be operated by the concreteclass :)

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.