Update .net core project

This commit is contained in:
sunkaixuan
2022-09-27 23:05:40 +08:00
parent f157043be0
commit 4e0359493d
13 changed files with 77 additions and 8 deletions

View File

@@ -22,6 +22,7 @@ namespace SqlSugar
var mappingEntity = this._Context.EntityMaintenance.GetEntityInfo(mappingType);
var mappingA = mappingEntity.Columns.FirstOrDefault(x => x.PropertyName == parentNavigateProperty.Navigat.MappingAId);
var mappingB = mappingEntity.Columns.FirstOrDefault(x => x.PropertyName == parentNavigateProperty.Navigat.MappingBId);
Check.ExceptionEasy(mappingA == null || mappingB == null, $"Navigate property {name} error ", $"导航属性{name}配置错误");
var mappingPk = mappingEntity.Columns
.Where(it => it.PropertyName != mappingA.PropertyName)
.Where(it => it.PropertyName != mappingB.PropertyName)

View File

@@ -22,6 +22,7 @@ namespace SqlSugar
var mappingEntity = this._Context.EntityMaintenance.GetEntityInfo(mappingType);
var mappingA = mappingEntity.Columns.FirstOrDefault(x=>x.PropertyName== parentNavigateProperty.Navigat.MappingAId);
var mappingB = mappingEntity.Columns.FirstOrDefault(x => x.PropertyName == parentNavigateProperty.Navigat.MappingBId);
Check.ExceptionEasy(mappingA == null || mappingB == null, $"Navigate property {name} error ", $"导航属性{name}配置错误");
var mappingPk = mappingEntity.Columns
.Where(it => it.PropertyName != mappingA.PropertyName)
.Where(it => it.PropertyName != mappingB.PropertyName)
@@ -33,7 +34,6 @@ namespace SqlSugar
.Where(it => !it.IsOnlyIgnoreInsert)
.Where(it => !it.IsIgnore)
.Where(it => !it.IsPrimarykey);
Check.Exception(mappingA == null || mappingB == null, $"Navigate property {name} error ", $"导航属性{name}配置错误");
List<Dictionary<string, object>> mappgingTables = new List<Dictionary<string, object>>();
foreach (var item in parentList)
{

View File

@@ -22,6 +22,7 @@ namespace SqlSugar
var mappingEntity = this._Context.EntityMaintenance.GetEntityInfo(mappingType);
var mappingA = mappingEntity.Columns.FirstOrDefault(x => x.PropertyName == parentNavigateProperty.Navigat.MappingAId);
var mappingB = mappingEntity.Columns.FirstOrDefault(x => x.PropertyName == parentNavigateProperty.Navigat.MappingBId);
Check.ExceptionEasy(mappingA == null || mappingB == null, $"Navigate property {name} error ", $"导航属性{name}配置错误");
var mappingPk = mappingEntity.Columns
.Where(it => it.PropertyName != mappingA.PropertyName)
.Where(it => it.PropertyName != mappingB.PropertyName)
@@ -33,7 +34,6 @@ namespace SqlSugar
.Where(it => !it.IsPrimarykey)
.Where(it => !it.IsOnlyIgnoreInsert)
.Where(it => !it.IsIgnore);
Check.Exception(mappingA == null || mappingB == null, $"Navigate property {name} error ", $"导航属性{name}配置错误");
List<Dictionary<string, object>> mappgingTables = new List<Dictionary<string, object>>();
var ids=new List<object>();
foreach (var item in parentList)

View File

@@ -201,8 +201,10 @@ namespace SqlSugar
var bEntity = navObjectNameColumnInfo.PropertyInfo.PropertyType.GetGenericArguments()[0];
var bEntityInfo = this.Context.EntityMaintenance.GetEntityInfo(bEntity);
var bPkColumn = bEntityInfo.Columns.FirstOrDefault(it => it.IsPrimarykey);
Check.ExceptionEasy(bPkColumn==null, $"{bEntityInfo.EntityName} need primary key", $"{bEntityInfo.EntityName} 实体需要配置主键");
this.Context.InitMappingInfo(bEntity);
var listItemPkColumn = listItemEntity.Columns.Where(it => it.IsPrimarykey).FirstOrDefault();
Check.ExceptionEasy(listItemPkColumn == null, $"{listItemEntity.EntityName} need primary key", $"{listItemEntity.EntityName} 实体需要配置主键");
var ids = list.Select(it => it.GetType().GetProperty(listItemPkColumn.PropertyName).GetValue(it)).Select(it => it == null ? "null" : it).Distinct().ToList();
var mappingEntity = this.Context.EntityMaintenance.GetEntityInfo(navObjectNameColumnInfo.Navigat.MappingType);
var aColumn = mappingEntity.Columns.First(it => it.PropertyName == navObjectNameColumnInfo.Navigat.MappingAId);
@@ -371,6 +373,7 @@ namespace SqlSugar
if (navObjectNameColumnInfo.Navigat.Name2.HasValue())
{
listItemPkColumn = listItemEntity.Columns.Where(it => it.PropertyName== navObjectNameColumnInfo.Navigat.Name2).FirstOrDefault();
Check.ExceptionEasy(listItemPkColumn == null, $"{navObjectNameColumnInfo.PropertyName} Navigate is error ", $"{navObjectNameColumnInfo.PropertyName}导航配置错误,可能顺序反了。");
}
var ids = list.Select(it => it.GetType().GetProperty(listItemPkColumn.PropertyName).GetValue(it)).Select(it => it == null ? "null" : it).Distinct().ToList();
List<IConditionalModel> conditionalModels = new List<IConditionalModel>();

View File

@@ -99,9 +99,17 @@ namespace SqlSugar
}
var value = model.Args[1].MemberName;
string inValueString = null;
var isNvarchar = model.Args.Count == 3;
if (inValues != null && inValues.Count > 0)
{
inValueString = inValues.ToArray().ToJoinSqlInVals();
{
if (isNvarchar&& model.Args[2].MemberValue.Equals(true))
{
inValueString = inValues.ToArray().ToJoinSqlInValsN();
}
else
{
inValueString = inValues.ToArray().ToJoinSqlInVals();
}
}
if (inValueString.IsNullOrEmpty())
{

View File

@@ -491,7 +491,7 @@ namespace SqlSugar
//var property=item.Type.GetProperties().Where(it => it.Name == newExpressionInfo.l).First();
//asName = GetAsName(item, newExpressionInfo.ShortName, property);
parameter.Context.Result.Append(this.Context.GetAsString(
this.Context.SqlTranslationLeft+asName + "." + newExpressionInfo.RightDbName+this.Context.SqlTranslationRight,
this.Context.SqlTranslationLeft+asName + "." + newExpressionInfo.LeftNameName+this.Context.SqlTranslationRight,
newExpressionInfo.ShortName+"."+newExpressionInfo.RightDbName
));
}

View File

@@ -149,8 +149,10 @@ namespace SqlSugar
private MapperSql GetManyToManySql()
{
var bPk = this.ProPertyEntity.Columns.First(it => it.IsPrimarykey == true).DbColumnName;
var aPk = this.EntityInfo.Columns.First(it => it.IsPrimarykey == true).DbColumnName;
var bPk = this.ProPertyEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true)?.DbColumnName;
var aPk = this.EntityInfo.Columns.FirstOrDefault(it => it.IsPrimarykey == true)?.DbColumnName;
Check.ExceptionEasy(aPk.IsNullOrEmpty(), $"{this.EntityInfo.EntityName}need primary key", $"{this.EntityInfo.EntityName}需要主键");
Check.ExceptionEasy(bPk.IsNullOrEmpty(), $"{this.ProPertyEntity.EntityName}need primary key", $"{this.ProPertyEntity.EntityName}需要主键");
MapperSql mapper = new MapperSql();
var queryable = this.context.Queryable<object>();
bPk = queryable.QueryBuilder.Builder.GetTranslationColumnName(bPk);

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SqlSugar
{
public enum AsNameFormatType
{
Default = 0,
NoConvert = 1
}
}

View File

@@ -10,6 +10,7 @@ namespace SqlSugar
ISugarQueryable<T> OrderBy(List<OrderByModel> models);
ISugarQueryable<T> GroupBy(List<GroupByModel> models);
ISugarQueryable<T> Select(List<SelectModel> models);
ISugarQueryable<T> Select(List<SelectModel> models,AsNameFormatType type);
ISugarQueryable<T> AS(string tableName, string shortName);
ISugarQueryable<T> AddJoinInfo(string tableName, string shortName, IFuncModel models, JoinType type = JoinType.Left);
ISugarQueryable<T> AddJoinInfo(List<JoinInfoParameter> joinInfoParameters);

View File

@@ -34,6 +34,10 @@ namespace SqlSugar
{
orderByModel.AsName = orderByModel.FiledName.ObjToString();
}
if (orderByModel.AsName.StartsWith(UtilConstants.ReplaceKey))
{
return orderByModel.AsName.Replace(UtilConstants.ReplaceKey, string.Empty);
}
return this.GetTranslationColumnName(orderByModel.AsName);
}

View File

@@ -57,6 +57,22 @@ namespace SqlSugar
this.QueryBuilder.Parameters.AddRange(orderObj.Value);
return this;
}
public ISugarQueryable<T> Select(List<SelectModel> models, AsNameFormatType type)
{
if (type == AsNameFormatType.NoConvert)
{
foreach (var model in models)
{
if (!string.IsNullOrEmpty(model.AsName))
{
model.AsName = (UtilConstants.ReplaceKey + SqlBuilder.SqlTranslationLeft + model.AsName + SqlBuilder.SqlTranslationRight);
model.AsName.ToCheckField();
}
}
}
return Select(models);
}
public ISugarQueryable<T> Having(IFuncModel model)
{
var orderObj = this.SqlBuilder.FuncModelToSql(model);

View File

@@ -38,3 +38,13 @@ namespace SqlSugar
}
}
}
namespace System.Collections.Generic
{
public static class EnumerableExtensions
{
public static bool Contains<T>(this IEnumerable<T> thisValue, T likeKey, bool isNvarchar)
{
return thisValue.Contains(likeKey);
}
}
}

View File

@@ -18,7 +18,17 @@ namespace SqlSugar
return string.Join(",", array.Where(c => c != null).Select(it => it.ToSqlValue()));
}
}
public static string ToJoinSqlInValsN<T>(this T[] array)
{
if (array == null || array.Length == 0)
{
return ToSqlValue(string.Empty);
}
else
{
return string.Join(",", array.Where(c => c != null).Select(it => "N"+it.ToSqlValue()));
}
}
public static string ToSqlValue(this object value)
{
if (value!=null&& UtilConstants.NumericalTypes.Contains(value.GetType()))