Install-Package Dapper Install-Package Microsoft.Extensions.Configuration Install-Package Microsoft.Extensions.DependencyInjection.Abstractions
通过NuGet,在数据库项目引用以上程序包
using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using Aps.Core.Interfaces.IBasicData; using Dapper; using Microsoft.Data.SqlClient; using Microsoft.Extensions.Configuration; namespace Aps.Infrastructure.Services; public class CustomerService : ICustomerService { private readonly IConfiguration _configuration; public CustomerService(IConfiguration configuration) { _configuration = configuration; } public async Task<int> BatchDelete(int id) { using var sqlConn = new SqlConnection(_configuration.GetConnectionString("DefaultConnection")); sqlConn.Open(); string sql = @"Delete Customers Where Id in (@ids)"; int result = await sqlConn.ExecuteAsync(sql,new {id= id }); return result; } }
标签:项目,System,id,引入,using,Dapper,configuration,Microsoft From: https://www.cnblogs.com/friend/p/17215676.html