最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

mysql批量插入BulkCopy的實(shí)現(xiàn)

 更新時(shí)間:2023年03月30日 11:22:18   作者:大熊程序猿  
本文主要介紹了mysql批量插入BulkCopy的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

一、新建項(xiàng)目:SqlSugarDemo

  <ItemGroup>
    <PackageReference Include="SqlSugarCore" Version="5.1.3.52" />
  </ItemGroup>

二、連接串未添加AllowLoadLocalInfile=true

中文提示 : BulkCopy MySql連接字符串需要添加 AllowLoadLocalInfile=true; 添加后如果還不行Mysql數(shù)據(jù)庫(kù)執(zhí)行一下 SET GLOBAL local_infile=1 
English Message : connection string add : AllowLoadLocalInfile=true

show global variables like 'local_infile';
SET GLOBAL local_infile=1 

 三、Startup.cs

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 =>
               {
                   //單例參數(shù)配置,所有上下文生效
                   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;
        }
    }
}

到此這篇關(guān)于mysql批量插入BulkCopy的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)mysql批量插入BulkCopy內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • mysql 8.0.12 安裝配置教程

    mysql 8.0.12 安裝配置教程

    這篇文章主要為大家詳細(xì)介紹了mysql 8.0.12安裝配置方法圖文教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-09-09
  • MySQL大表數(shù)據(jù)的分區(qū)與分庫(kù)分表的實(shí)現(xiàn)

    MySQL大表數(shù)據(jù)的分區(qū)與分庫(kù)分表的實(shí)現(xiàn)

    數(shù)據(jù)庫(kù)的分區(qū)和分庫(kù)分表是兩種常用的技術(shù)方案,本文主要介紹了MySQL大表數(shù)據(jù)的分區(qū)與分庫(kù)分表的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2025-03-03
  • Mysql巧用join優(yōu)化sql的方法詳解

    Mysql巧用join優(yōu)化sql的方法詳解

    這篇文章主要給大家介紹了關(guān)于Mysql巧用join優(yōu)化sql的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Mysql具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-08-08
  • 最新評(píng)論

    新巴尔虎左旗| 无锡市| 中江县| 砚山县| 白玉县| 八宿县| 崇州市| 大新县| 镇沅| 青州市| 马鞍山市| 中牟县| 朝阳县| 体育| 上杭县| 永济市| 清水县| 双鸭山市| 随州市| 杭锦后旗| 杂多县| 泽普县| 喀什市| 永嘉县| 黄大仙区| 临湘市| 青龙| 信宜市| 湾仔区| 泰州市| 布拖县| 娱乐| 嘉峪关市| 通榆县| 利川市| 申扎县| 恭城| 四平市| 永城市| 南溪县| 林芝县|