ASP. NET core uses dapper Operation Sqlserver/oracle

Source: Internet
Author: User
Tags log4net

No nonsense, or first git. Address: Https://gitee.com/jimmyTown_admin_admin/DapperInCoreDemo.git

The structure is as follows:

1. In the framework era, Dapper was heavily used and developed by many programmers because of its small, light but easy-to-use and efficient use. Compared to the pet of EF, I also prefer to use dapper, today just have a free, I wrote the corresponding Deamo (Demo 2 part, part of the. NET Core console, part of ASP.

Development environment: VS2017. NET Core 2.1.3 IIS7.

2. Structure Description:

Dapperincorelib references in Dapper

Oracle.ManagedDataAccess.Core

After referencing OK, the corresponding generic interface is defined according to the dapper package

Mainly for the implementation of dapper itself for some curd package

1.2 Next to the interface for the corresponding implementation, here will consider compatible with sqlserver/oracle or other db (currently only implemented in these 2, but actually also support mysql/sqlite, etc.)

The corresponding connection string and connection type are used to drive the implementation.

For example, when the query is directly using idbconection as the connection, the other part of the same

1.3 Dapperfactory

There are 2 main blocks here.

The first part implements the singleton: access point for all connections

Part II: Obtaining an interface for operations

1. 4 Simple Warehousing implementation

Interface section (slightly, please look directly at the code), the implementation section:

Then look at part 2nd: the corresponding Webapi section (main 1. Injection 2.Swagger, 3.log4net)

Introduction of Swashbuckle.aspnetcore and Log4net

2.1 Configuring IOC injection and swagger

2.2 Configuring Log4net

Of course, the log can also be used without the use of log4net and Microsoft.Extensions.Logging under the Iloggerfactory

Run a look at the effect (I'll change the start URL in Lauchsetting.json to "Launchurl": "Api/student"

Show all student information by default, we can go to Swagger page

Here is not a try, you can download the code to try

ASP. NET core uses dapper Operation Sqlserver/oracle

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.