Database component Hxj.data (29) (recommended by Dbsession)

Source: Internet
Author: User

Examples in a series of articles are dbsession.default as the entry point for manipulating data.

Default is the configuration that reads the last node of the connectionstrings node in the config file.

It is also recommended to create a dbsession in the actual project.

Can be written as follows:

public class Db
{
public readonly static DbSession Northwind = new DbSession ("NorthwindConnectionString");
static Db()
{
Northwind.RegisterSqlLogger(delegate(string sql)
{
File.AppendAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "sqllog.txt"), sql);
});
}
}

This is the db.northwind as the entrance. There will be multiple connections in the project, as well as reference to similar wording. Inside the static constructor is a registration event to record the execution of SQL scripts to facilitate debugging and viewing. However, the log file will be more and more large, so write log SQL method needs to be modified, if you do not need to log the code comments can be. Of course, use log4net to write, there is no need to consider so much.

Northwind.RegisterSqlLogger(delegate(string sql)
{
Hxj.Common.Log4net.debug(sql);
});

End of this section.

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.