您好,登錄后才能下訂單哦!
這篇文章主要介紹了mysql批量插入BulkCopy如何實現的相關知識,內容詳細易懂,操作簡單快捷,具有一定借鑒價值,相信大家閱讀完這篇mysql批量插入BulkCopy如何實現文章都會有所收獲,下面我們一起來看看吧。
<ItemGroup> <PackageReference Include="SqlSugarCore" Version="5.1.3.52" /> </ItemGroup>
中文提示 : BulkCopy MySql連接字符串需要添加 AllowLoadLocalInfile=true; 添加后如果還不行Mysql數據庫執行一下 SET GLOBAL local_infile=1
English Message : connection string add : AllowLoadLocalInfile=true
show global variables like 'local_infile'; SET GLOBAL local_infile=1
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace WebApplication3 { public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddSingleton<ISqlSugarClient>(s => { SqlSugarScope sqlSugar = new SqlSugarScope(new ConnectionConfig() { DbType = SqlSugar.DbType.MySql, ConnectionString = "Server=192.168.31.132;User ID=root;Password=123456;Database=sugar;port=3306;AllowLoadLocalInfile=true", IsAutoCloseConnection = true, }, db => { //單例參數配置,所有上下文生效 db.Aop.OnLogExecuting = (sql, pars) => { }; }); return sqlSugar; }); services.AddControllersWithViews(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); } } }
HomeController.cs
using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using SqlSugar; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading.Tasks; using WebApplication3.Models; namespace WebApplication3.Controllers { public class HomeController : Controller { private readonly ILogger<HomeController> _logger; private readonly ISqlSugarClient _sqlSugarClient; public HomeController(ILogger<HomeController> logger, ISqlSugarClient sqlSugarClient) { _logger = logger; _sqlSugarClient = sqlSugarClient; } public IActionResult Index() { _sqlSugarClient.Fastest<RealmAuctionDatum>().BulkCopy(GetList()); return View(); } public List<RealmAuctionDatum> GetList() { var datas = new List<RealmAuctionDatum>(); for (int i = 0; i < 10000; i++) { datas.Add(new RealmAuctionDatum { Name = Guid.NewGuid().ToString("N") }); } return datas; } } }
關于“mysql批量插入BulkCopy如何實現”這篇文章的內容就介紹到這里,感謝各位的閱讀!相信大家對“mysql批量插入BulkCopy如何實現”知識都有一定的了解,大家如果還想學習更多知識,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。