Update Core

This commit is contained in:
sunkaixuan 2017-09-21 11:17:07 +08:00
parent 0aa7641735
commit 039e78a31a
6 changed files with 21 additions and 4 deletions

View File

@ -216,6 +216,13 @@ namespace SqlSugar
resolveExpress.MappingColumns = Context.MappingColumns;
resolveExpress.MappingTables = Context.MappingTables;
resolveExpress.IgnoreComumnList = Context.IgnoreColumns;
resolveExpress.InitMappingInfo = this.Context.InitMppingInfo;
resolveExpress.RefreshMapping = () =>
{
resolveExpress.MappingColumns = Context.MappingColumns;
resolveExpress.MappingTables = Context.MappingTables;
resolveExpress.IgnoreComumnList = Context.IgnoreColumns;
};
resolveExpress.Resolve(expression, resolveType);
this.Parameters.AddRange(resolveExpress.Parameters);
var reval = resolveExpress.Result;

View File

@ -28,9 +28,9 @@ namespace SqlSugar
public int ExecuteCommand()
{
PreToSql();
Check.Exception(UpdateBuilder.WhereValues.IsNullOrEmpty() && GetPrimaryKeys().IsNullOrEmpty(), "You cannot have no primary key and no conditions");
string sql = UpdateBuilder.ToSqlString();
RestoreMapping();
Check.Exception(UpdateBuilder.WhereValues.IsNullOrEmpty() && GetPrimaryKeys().IsNullOrEmpty(), "You cannot have no primary key and no conditions");
return this.Ado.ExecuteCommand(sql, UpdateBuilder.Parameters == null ? null : UpdateBuilder.Parameters.ToArray());
}
public Task<int> ExecuteCommandAsync()

View File

@ -99,6 +99,8 @@ namespace SqlSugar
}
public virtual string SqlTranslationLeft { get { return "["; } }
public virtual string SqlTranslationRight { get { return "]"; } }
public virtual Action<Type> InitMappingInfo { get; set; }
public virtual Action RefreshMapping { get; set; }
#endregion
#region Core methods
@ -143,7 +145,7 @@ namespace SqlSugar
else if (isMapping)
{
var mappingInfo = this.MappingTables.FirstOrDefault(it => it.EntityName.Equals(entityName, StringComparison.CurrentCultureIgnoreCase));
return SqlTranslationLeft + (mappingInfo == null ? entityName : mappingInfo.EntityName) + SqlTranslationRight;
return SqlTranslationLeft + (mappingInfo == null ? entityName : mappingInfo.DbTableName) + SqlTranslationRight;
}
else if (isComplex)
{

View File

@ -38,7 +38,13 @@ namespace SqlSugar
{
var exp = expression as MethodCallExpression;
var resType = exp.Method.ReturnType;
var name = resType.GetGenericArguments().First().Name;
var entityType = resType.GetGenericArguments().First();
var name = entityType.Name;
if (this.Context.InitMappingInfo != null)
{
this.Context.InitMappingInfo(entityType);
this.Context.RefreshMapping();
}
return "FROM "+this.Context.GetTranslationTableName(name, true);
}
}

View File

@ -22,6 +22,8 @@ namespace SqlSugar
ExpressionResult Result { get; set; }
string SqlParameterKeyWord { get; }
string SingleTableNameSubqueryShortName { get; set; }
Action<Type> InitMappingInfo { get; set; }
Action RefreshMapping { get; set; }
string GetAsString(string fieldName, string fieldValue);
void Resolve(Expression expression, ResolveExpressType resolveType);

View File

@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>4.5.2.6</Version>
<Version>4.5.2.8</Version>
<Copyright>sun_kai_xuan</Copyright>
<PackageProjectUrl>https://github.com/sunkaixuan/SqlSugar</PackageProjectUrl>
<PackageLicenseUrl></PackageLicenseUrl>