mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-19 18:22:23 +08:00
Update exp to sql
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using OrmTest.Models;
|
||||
using SqlSugar;
|
||||
using sugarentity;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -174,6 +175,13 @@ namespace OrmTest.BugTest
|
||||
AbleQty = ts.FQty - SqlFunc.Subqueryable<TTempStock>().Where(s => s.FMICode == vmg.FMICode && s.FK_Store == "")
|
||||
.Select(s => SqlFunc.AggregateSum(s.FKCSL))
|
||||
}).ToList();
|
||||
DB.CodeFirst.InitTables<h5linkpassloginfo, logtype>();
|
||||
DB.Updateable<h5linkpassloginfo>().UpdateColumns(it =>
|
||||
new h5linkpassloginfo()
|
||||
{
|
||||
LogKeyId = SqlFunc.Subqueryable<logtype>().Where(s => s.LogKey == "openpage").Select(s => s.Id),
|
||||
StrVal = "sdsdsdsd"
|
||||
}).Where(it => it.Id == 1).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
|
148
Src/Asp.Net/SqlServerTest/BugTest/BugModels/h5linkpassloginfo.cs
Normal file
148
Src/Asp.Net/SqlServerTest/BugTest/BugModels/h5linkpassloginfo.cs
Normal file
@@ -0,0 +1,148 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using SqlSugar;
|
||||
|
||||
namespace sugarentity
|
||||
{
|
||||
///<summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarTable("h5linkpassloginfo")]
|
||||
public partial class h5linkpassloginfo
|
||||
{
|
||||
public h5linkpassloginfo()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Desc:
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public int LogKeyId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public string SessionId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public int UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:0:外部用户 1:内部用户
|
||||
/// Default:0
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public byte Inside { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public int H5PackageId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public int LinkPassId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public int LinkType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:
|
||||
/// Default:NULL
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public int? LinkBusinessTemplateId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:
|
||||
/// Default:NULL
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public int? LinkBusinessObjectId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:
|
||||
/// Default:NULL
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public int? IntVal { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:
|
||||
/// Default:NULL
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string StrVal { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:
|
||||
/// Default:NULL
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string JsonVal { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public int ClientIP { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public int ServerIP { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public string UserAgentHashKey { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:
|
||||
/// Default:NULL
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string OtherLogsGuid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:
|
||||
/// Default:current_timestamp()
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
public DateTime Intime { get; set; }
|
||||
|
||||
}
|
||||
}
|
64
Src/Asp.Net/SqlServerTest/BugTest/BugModels/logtype.cs
Normal file
64
Src/Asp.Net/SqlServerTest/BugTest/BugModels/logtype.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using SqlSugar;
|
||||
|
||||
namespace sugarentity
|
||||
{
|
||||
///<summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarTable("logtype")]
|
||||
public partial class logtype
|
||||
{
|
||||
public logtype()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Desc:
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public string LogKey { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:
|
||||
/// Default:NULL
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string KeyName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:
|
||||
/// Default:NULL
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:0:否 1:是
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public byte IsKeyNode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:
|
||||
/// Default:current_timestamp()
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
public DateTime InTime { get; set; }
|
||||
|
||||
}
|
||||
}
|
@@ -53,8 +53,10 @@
|
||||
<Compile Include="BugTest\BugModels\AccountsModel.cs" />
|
||||
<Compile Include="BugTest\BugModels\ClientsModel.cs" />
|
||||
<Compile Include="BugTest\BugModels\ExposureModel.cs" />
|
||||
<Compile Include="BugTest\BugModels\h5linkpassloginfo.cs" />
|
||||
<Compile Include="BugTest\BugModels\JewelsModel.cs" />
|
||||
<Compile Include="BugTest\BugModels\LevelSettingModel.cs" />
|
||||
<Compile Include="BugTest\BugModels\logtype.cs" />
|
||||
<Compile Include="BugTest\BugModels\tLogonHistoryModel.cs" />
|
||||
<Compile Include="BugTest\BugModels\VipAccountsModel.cs" />
|
||||
<Compile Include="BugTest\BugModels\VipBenefitsModel.cs" />
|
||||
|
@@ -22,7 +22,8 @@ namespace SqlSugar
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual ICodeFirst SetStringDefaultLength(int length) {
|
||||
public virtual ICodeFirst SetStringDefaultLength(int length)
|
||||
{
|
||||
DefultLength = length;
|
||||
return this;
|
||||
}
|
||||
@@ -43,7 +44,23 @@ namespace SqlSugar
|
||||
});
|
||||
Check.Exception(!executeResult.IsSuccess, executeResult.ErrorMessage);
|
||||
}
|
||||
public virtual void InitTables(Type[] entityTypes)
|
||||
public void InitTables<T>()
|
||||
{
|
||||
InitTables(typeof(T));
|
||||
}
|
||||
public void InitTables<T, T2>()
|
||||
{
|
||||
InitTables(typeof(T),typeof(T2));
|
||||
}
|
||||
public void InitTables<T, T2, T3>()
|
||||
{
|
||||
InitTables(typeof(T), typeof(T2),typeof(T3));
|
||||
}
|
||||
public void InitTables<T, T2, T3, T4>()
|
||||
{
|
||||
InitTables(typeof(T), typeof(T2), typeof(T3),typeof(T4));
|
||||
}
|
||||
public virtual void InitTables(params Type[] entityTypes)
|
||||
{
|
||||
if (entityTypes.HasValue())
|
||||
{
|
||||
@@ -74,10 +91,12 @@ namespace SqlSugar
|
||||
protected virtual void Execute(Type entityType)
|
||||
{
|
||||
var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(entityType);
|
||||
if (this.DefultLength > 0) {
|
||||
if (this.DefultLength > 0)
|
||||
{
|
||||
foreach (var item in entityInfo.Columns)
|
||||
{
|
||||
if (item.PropertyInfo.PropertyType == UtilConstants.StringType && item.DataType.IsNullOrEmpty()&& item.Length==0) {
|
||||
if (item.PropertyInfo.PropertyType == UtilConstants.StringType && item.DataType.IsNullOrEmpty() && item.Length == 0)
|
||||
{
|
||||
item.Length = DefultLength;
|
||||
}
|
||||
}
|
||||
@@ -98,13 +117,13 @@ namespace SqlSugar
|
||||
List<DbColumnInfo> columns = new List<DbColumnInfo>();
|
||||
if (entityInfo.Columns.HasValue())
|
||||
{
|
||||
foreach (var item in entityInfo.Columns.OrderBy(it=>it.IsPrimarykey?0:1).Where(it => it.IsIgnore == false))
|
||||
foreach (var item in entityInfo.Columns.OrderBy(it => it.IsPrimarykey ? 0 : 1).Where(it => it.IsIgnore == false))
|
||||
{
|
||||
DbColumnInfo dbColumnInfo = EntityColumnToDbColumn(entityInfo, tableName, item);
|
||||
columns.Add(dbColumnInfo);
|
||||
}
|
||||
}
|
||||
this.Context.DbMaintenance.CreateTable(tableName, columns,true);
|
||||
this.Context.DbMaintenance.CreateTable(tableName, columns, true);
|
||||
}
|
||||
public virtual void ExistLogic(EntityInfo entityInfo)
|
||||
{
|
||||
@@ -136,7 +155,7 @@ namespace SqlSugar
|
||||
.ToList();
|
||||
|
||||
|
||||
var isMultiplePrimaryKey = dbColumns.Where(it => it.IsPrimarykey).Count() > 1|| entityColumns.Where(it => it.IsPrimarykey).Count() > 1;
|
||||
var isMultiplePrimaryKey = dbColumns.Where(it => it.IsPrimarykey).Count() > 1 || entityColumns.Where(it => it.IsPrimarykey).Count() > 1;
|
||||
|
||||
|
||||
var isChange = false;
|
||||
@@ -167,7 +186,7 @@ namespace SqlSugar
|
||||
if (dbColumn == null) continue;
|
||||
bool pkDiff, idEntityDiff;
|
||||
KeyAction(item, dbColumn, out pkDiff, out idEntityDiff);
|
||||
if (dbColumn != null && pkDiff && !idEntityDiff&& isMultiplePrimaryKey==false)
|
||||
if (dbColumn != null && pkDiff && !idEntityDiff && isMultiplePrimaryKey == false)
|
||||
{
|
||||
var isAdd = item.IsPrimarykey;
|
||||
if (isAdd)
|
||||
@@ -179,15 +198,17 @@ namespace SqlSugar
|
||||
this.Context.DbMaintenance.DropConstraint(tableName, string.Format("PK_{0}_{1}", tableName, item.DbColumnName));
|
||||
}
|
||||
}
|
||||
else if ((pkDiff || idEntityDiff)&& isMultiplePrimaryKey==false)
|
||||
else if ((pkDiff || idEntityDiff) && isMultiplePrimaryKey == false)
|
||||
{
|
||||
ChangeKey(entityInfo, tableName, item);
|
||||
}
|
||||
}
|
||||
if (isMultiplePrimaryKey) {
|
||||
var oldPkNames = dbColumns.Where(it => it.IsPrimarykey).Select(it => it.DbColumnName.ToLower()).OrderBy(it=>it).ToList();
|
||||
var newPkNames = entityColumns.Where(it => it.IsPrimarykey).Select(it => it.DbColumnName.ToLower()).OrderBy(it=>it).ToList();
|
||||
if (!Enumerable.SequenceEqual(oldPkNames,newPkNames)) {
|
||||
if (isMultiplePrimaryKey)
|
||||
{
|
||||
var oldPkNames = dbColumns.Where(it => it.IsPrimarykey).Select(it => it.DbColumnName.ToLower()).OrderBy(it => it).ToList();
|
||||
var newPkNames = entityColumns.Where(it => it.IsPrimarykey).Select(it => it.DbColumnName.ToLower()).OrderBy(it => it).ToList();
|
||||
if (!Enumerable.SequenceEqual(oldPkNames, newPkNames))
|
||||
{
|
||||
Check.Exception(true, ErrorMessage.GetThrowMessage("Modification of multiple primary key tables is not supported. Delete tables while creating", "不支持修改多主键表,请删除表在创建"));
|
||||
}
|
||||
|
||||
|
@@ -121,6 +121,14 @@ namespace SqlSugar
|
||||
resolveExpress.IgnoreComumnList = Context.IgnoreColumns;
|
||||
resolveExpress.SqlFuncServices = Context.CurrentConnectionConfig.ConfigureExternalServices == null ? null : Context.CurrentConnectionConfig.ConfigureExternalServices.SqlFuncServices;
|
||||
}
|
||||
resolveExpress.InitMappingInfo = Context.InitMppingInfo;
|
||||
resolveExpress.RefreshMapping = () =>
|
||||
{
|
||||
resolveExpress.MappingColumns = Context.MappingColumns;
|
||||
resolveExpress.MappingTables = Context.MappingTables;
|
||||
resolveExpress.IgnoreComumnList = Context.IgnoreColumns;
|
||||
resolveExpress.SqlFuncServices = Context.CurrentConnectionConfig.ConfigureExternalServices == null ? null : Context.CurrentConnectionConfig.ConfigureExternalServices.SqlFuncServices;
|
||||
};
|
||||
resolveExpress.Resolve(expression, resolveType);
|
||||
this.Parameters.AddRange(resolveExpress.Parameters);
|
||||
var result = resolveExpress.Result;
|
||||
|
@@ -162,7 +162,15 @@ namespace SqlSugar
|
||||
else if (isMapping)
|
||||
{
|
||||
var mappingInfo = this.MappingTables.FirstOrDefault(it => it.EntityName.Equals(entityName, StringComparison.CurrentCultureIgnoreCase));
|
||||
return SqlTranslationLeft + (mappingInfo == null ? entityName : mappingInfo.DbTableName) + SqlTranslationRight;
|
||||
var name = (mappingInfo == null ? entityName : mappingInfo.DbTableName);
|
||||
if (name.Contains("."))
|
||||
{
|
||||
return string.Join(".", name.Split('.').Select(it => SqlTranslationLeft + it + SqlTranslationRight));
|
||||
}
|
||||
else
|
||||
{
|
||||
return SqlTranslationLeft + name + SqlTranslationRight;
|
||||
}
|
||||
}
|
||||
else if (isComplex)
|
||||
{
|
||||
|
@@ -126,7 +126,15 @@ namespace SqlSugar
|
||||
var subSql = base.Context.GetEqString(memberName, parameter.CommonTempData.ObjToString());
|
||||
if (ResolveExpressType.Update == this.Context.ResolveType)
|
||||
{
|
||||
subSql = Regex.Replace(subSql, @" \[\w+?\]\.| ""\w+?""\.| \`\w+?\`\.", this.Context.GetTranslationTableName(parameter.CurrentExpression.Type.Name,true) +".");
|
||||
string name = this.Context.GetTranslationTableName(parameter.CurrentExpression.Type.Name, true);
|
||||
if (name.Contains("."))
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
subSql = Regex.Replace(subSql, @" \[\w+?\]\.| ""\w+?""\.| \`\w+?\`\.", name + ".");
|
||||
}
|
||||
}
|
||||
parameter.Context.Result.Append(subSql);
|
||||
});
|
||||
|
@@ -50,7 +50,7 @@ namespace SqlSugar
|
||||
this.Context.InitMappingInfo(entityType);
|
||||
this.Context.RefreshMapping();
|
||||
}
|
||||
var result= "FROM "+this.Context.GetTranslationTableName(name, true);
|
||||
var result= "FROM "+this.Context.GetTranslationTableName(name,true);
|
||||
if (this.Context.SubQueryIndex > 0) {
|
||||
result += " subTableIndex"+this.Context.SubQueryIndex;
|
||||
}
|
||||
|
@@ -7,11 +7,15 @@ namespace SqlSugar
|
||||
public partial interface ICodeFirst
|
||||
{
|
||||
SqlSugarClient Context { get; set; }
|
||||
ICodeFirst BackupTable(int maxBackupDataRows=int.MaxValue);
|
||||
ICodeFirst BackupTable(int maxBackupDataRows = int.MaxValue);
|
||||
ICodeFirst SetStringDefaultLength(int length);
|
||||
void InitTables(string entitiesNamespace);
|
||||
void InitTables(string [] entitiesNamespaces);
|
||||
void InitTables(params Type [] entityTypes);
|
||||
void InitTables(string[] entitiesNamespaces);
|
||||
void InitTables(params Type[] entityTypes);
|
||||
void InitTables(Type entityType);
|
||||
void InitTables<T>();
|
||||
void InitTables<T, T2>();
|
||||
void InitTables<T, T2, T3>();
|
||||
void InitTables<T, T2, T3, T4>();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user