测试 sqlserver mysql 的批量处理
This commit is contained in:
parent
7fa788d47e
commit
778f3e04f6
@ -1,4 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using AutoMapper;
|
||||
using HHWMS.Web.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
|
||||
@ -30,6 +32,15 @@ namespace HHWMS.Web
|
||||
[HttpPost]
|
||||
public IActionResult RequestIn(WcsRequest request)
|
||||
{
|
||||
var inv = new List<Inventory>();
|
||||
for (int i = 0; i < 10; i++)
|
||||
inv.Add(new Inventory
|
||||
{
|
||||
ContainerCode = "test" + i
|
||||
});
|
||||
//_unitwork.BatchAdd<Inventory>(inv);
|
||||
_unitwork.DeleteById<Inventory>(1441);
|
||||
//_unitwork.BatchUpdate<Inventory>(x => x.ID > 1030, x=>new Inventory { Batch = "test"});
|
||||
return ApiResult();
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,6 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using HHWMS.Web.Models;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using Z.EntityFramework.Plus;
|
||||
|
||||
namespace HHWMS.Web
|
||||
{
|
||||
|
||||
@ -37,6 +37,7 @@
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="SoapCore" Version="1.1.0.38" />
|
||||
<PackageReference Include="SqlSugarCore" Version="5.1.4.143" />
|
||||
<PackageReference Include="System.ServiceModel.Duplex" Version="4.10.*" />
|
||||
<PackageReference Include="System.ServiceModel.Federation" Version="4.10.*" />
|
||||
<PackageReference Include="System.ServiceModel.Http" Version="4.10.*" />
|
||||
@ -45,7 +46,7 @@
|
||||
<PackageReference Include="WalkingTec.Mvvm.Core" Version="6.3.7-alpha" />
|
||||
<PackageReference Include="WalkingTec.Mvvm.Mvc" Version="6.3.7-alpha" />
|
||||
<PackageReference Include="WalkingTec.Mvvm.TagHelpers.LayUI" Version="6.3.7-alpha" />
|
||||
<PackageReference Include="Z.EntityFramework.Plus.EFCore" Version="6.16.1" />
|
||||
<PackageReference Include="Z.EntityFramework.Plus.EFCore" Version="6.102.1.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ProjectExtensions><VisualStudio><UserProperties appsettings_1json__JsonSchema="" /></VisualStudio></ProjectExtensions>
|
||||
|
||||
@ -71,12 +71,10 @@ namespace HHWMS.Web.Models
|
||||
public string SupplierCode { get; set; }
|
||||
|
||||
[Display(Name = "Inventory.TaskQty", Description = "任务数量")]
|
||||
[StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")]
|
||||
[Column(TypeName = "decimal(12,4)")]
|
||||
public decimal? TaskQty { get; set; }
|
||||
|
||||
[Display(Name = "Inventory.Qty", Description = "数量")]
|
||||
[StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")]
|
||||
[Column(TypeName = "decimal(12,4)")]
|
||||
public decimal? Qty { get; set; }
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
@ -20,7 +21,7 @@ namespace HHWMS.Web
|
||||
|
||||
int Add<T>(T entity) where T : class;
|
||||
|
||||
int BatchAdd<T>(T[] entities) where T : class;
|
||||
int BatchAdd<T>(IEnumerable<T> entities) where T : class;
|
||||
|
||||
/// <summary>
|
||||
/// 添加到历史表,并将原数据删除
|
||||
@ -33,7 +34,7 @@ namespace HHWMS.Web
|
||||
|
||||
int Update<T>(T entity) where T : class;
|
||||
|
||||
int BatchUpdate<T>(T[] entities) where T : class;
|
||||
int BatchUpdate<T>(IEnumerable<T> entities) where T : class;
|
||||
/// <summary>
|
||||
/// 根据条件更新
|
||||
/// </summary>
|
||||
@ -57,7 +58,7 @@ namespace HHWMS.Web
|
||||
|
||||
int DeleteById<T>(int id) where T : class;
|
||||
|
||||
int BatchDelete<T>(T[] entities) where T : class;
|
||||
int BatchDelete<T>(IEnumerable<T> entities) where T : class;
|
||||
|
||||
string GetSerialNumber(string prefix, int length = 4);
|
||||
}
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using HHWMS.Web.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NPOI.POIFS.FileSystem;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using WalkingTec.Mvvm.Core.Extensions;
|
||||
using Z.EntityFramework.Plus;
|
||||
@ -20,6 +22,8 @@ namespace HHWMS.Web
|
||||
_info = context.LoginUserInfo;
|
||||
}
|
||||
|
||||
#region find
|
||||
|
||||
public T FindSingle<T>(Expression<Func<T, bool>> where) where T : class
|
||||
{
|
||||
return _data.Set<T>().AsNoTracking().FirstOrDefault(where);
|
||||
@ -47,9 +51,13 @@ namespace HHWMS.Web
|
||||
|
||||
public int GetCount<T>(Expression<Func<T, bool>> where) where T : class
|
||||
{
|
||||
return _data.Set<T>().Where(where).Count();
|
||||
return _data.Set<T>().Count(where);
|
||||
}
|
||||
|
||||
#endregion find
|
||||
|
||||
#region insert
|
||||
|
||||
public new int Add<T>(T entity) where T : class
|
||||
{
|
||||
if (typeof(T).IsSubclassOf(typeof(BasePoco)))
|
||||
@ -67,7 +75,7 @@ namespace HHWMS.Web
|
||||
return _data.SaveChanges();
|
||||
}
|
||||
|
||||
public int BatchAdd<T>(T[] entities) where T : class
|
||||
public int BatchAdd<T>(IEnumerable<T> entities) where T : class
|
||||
{
|
||||
foreach (T entity in entities)
|
||||
{
|
||||
@ -90,16 +98,13 @@ namespace HHWMS.Web
|
||||
|
||||
public int AddToHistory<T>(string name, Expression<Func<T, bool>> where, Expression<Func<T, object>> entity) where T : class
|
||||
{
|
||||
var query = _data.Set<T>().Where(where);
|
||||
var count = query.InsertFromQuery(typeof(T).Name + "History", entity);
|
||||
var count1 = _data.Set<T>().DeleteRangeByKey(query.ToArray());
|
||||
if(count == count1)
|
||||
{
|
||||
return count;
|
||||
}
|
||||
return 0;
|
||||
return _data.Set<T>().Where(where).InsertFromQuery(name,entity);
|
||||
}
|
||||
|
||||
#endregion insert
|
||||
|
||||
#region update
|
||||
|
||||
public new int Update<T>(T entity) where T : class
|
||||
{
|
||||
if (typeof(T).IsSubclassOf(typeof(BasePoco)))
|
||||
@ -111,7 +116,7 @@ namespace HHWMS.Web
|
||||
return _data.SaveChanges();
|
||||
}
|
||||
|
||||
public int BatchUpdate<T>(T[] entities) where T : class
|
||||
public int BatchUpdate<T>(IEnumerable<T> entities) where T : class
|
||||
{
|
||||
foreach (T entity in entities)
|
||||
{
|
||||
@ -134,40 +139,61 @@ namespace HHWMS.Web
|
||||
|
||||
public int BatchUpdate<T>(Expression<Func<T, bool>> where, Expression<Func<T, T>> entity) where T : class
|
||||
{
|
||||
/*if (typeof(T).IsSubclassOf(typeof(BasePoco)))
|
||||
{
|
||||
(entity as BasePoco).UpdateTime = DateTime.Now;
|
||||
(entity as BasePoco).UpdateBy = _info?.ITCode;
|
||||
}*/
|
||||
return _data.Set<T>().Where(where).Update(entity);
|
||||
}
|
||||
|
||||
#endregion update
|
||||
|
||||
#region delete
|
||||
|
||||
public int Delete<T>(T entity) where T : class
|
||||
{
|
||||
_data.Set<T>().Remove(entity);
|
||||
return _data.SaveChanges();
|
||||
}
|
||||
|
||||
public int BatchDelete<T>(IEnumerable<T> entities) where T : class
|
||||
{
|
||||
if (_data.DBType.Equals(DBTypeEnum.SqlServer))
|
||||
{
|
||||
return _data.Set<T>().DeleteRangeByKey(entities);
|
||||
}
|
||||
else
|
||||
{
|
||||
_data.Set<T>().RemoveRange(entities);
|
||||
return _data.SaveChanges();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int BatchDelete<T>(Expression<Func<T, bool>> where) where T : class
|
||||
{
|
||||
var query = _data.Set<T>().Where(where);
|
||||
return _data.Set<T>().DeleteRangeByKey(query.ToArray());
|
||||
return _data.Set<T>().Where(where).Delete();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 测试 不支持mysql
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
public int DeleteById<T>(T entity) where T : class
|
||||
{
|
||||
return _data.Set<T>().DeleteByKey(entity);
|
||||
return _data.Set<T>().DeleteByKey((entity as BasePoco).ID);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 测试 不支持mysql
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public int DeleteById<T>(int id) where T : class
|
||||
{
|
||||
return _data.Set<T>().DeleteByKey(id);
|
||||
}
|
||||
|
||||
public int BatchDelete<T>(T[] entities) where T : class
|
||||
{
|
||||
return _data.Set<T>().DeleteRangeByKey(entities);
|
||||
}
|
||||
#endregion delete
|
||||
|
||||
public string GetSerialNumber(string prefix, int length = 4)
|
||||
{
|
||||
|
||||
@ -22,17 +22,17 @@
|
||||
},
|
||||
|
||||
"Connections": [
|
||||
//{
|
||||
// "Key": "default",
|
||||
// "Value": "Server=127.0.0.1;Port=3306;Database=8357wms;Uid=root;Password=abc123*;Character Set=utf8mb4;",
|
||||
// "DBType": "mysql"
|
||||
//}
|
||||
{
|
||||
"Key": "default",
|
||||
"Value": "Data Source=.;Initial Catalog=8357wms;User=sa;Password=abc123*;Persist Security Info=True",
|
||||
"DbContext": "DataContext",
|
||||
"DBType": "sqlserver" //DataBase, you can choose mysql,sqlserver,pgsql,sqlite,oracle
|
||||
}
|
||||
"Value": "Server=127.0.0.1;Port=3306;Database=8357wms;Uid=root;Password=abc123*;Character Set=utf8mb4;",
|
||||
"DBType": "mysql"
|
||||
},
|
||||
//{
|
||||
// "Key": "default",
|
||||
// "Value": "Data Source=.;Initial Catalog=8357wms;User=sa;Password=abc123*;Persist Security Info=True",
|
||||
// "DbContext": "DataContext",
|
||||
// "DBType": "sqlserver" //DataBase, you can choose mysql,sqlserver,pgsql,sqlite,oracle
|
||||
//}
|
||||
//{
|
||||
// "Key": "default",
|
||||
// "Value": "Data Source=10.18.106.4;Initial Catalog=8357wms;User=wms;Password=abc123*;Persist Security Info=True",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user