mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 10:42:52 +08:00
- 优化 ServerTime 与 IUpdate.Set 指定更新的问题;#1251
This commit is contained in:
parent
0e6945cf76
commit
f8f31df120
@ -351,6 +351,21 @@ namespace base_entity
|
||||
public int aa { get; set; }
|
||||
}
|
||||
|
||||
public class JoinConditionAttribute : Attribute
|
||||
{
|
||||
public string Condition { get; set; }
|
||||
public JoinConditionAttribute(string condition) => Condition = condition;
|
||||
}
|
||||
public class JoinTest01
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string code { get; set; }
|
||||
public string parentcode { get; set; }
|
||||
public string name { get; set; }
|
||||
|
||||
[JoinCondition("a.parentcode = b.code")]
|
||||
public JoinTest01 Parent { get; set; }
|
||||
}
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
@ -409,6 +424,52 @@ namespace base_entity
|
||||
BaseEntity.Initialization(fsql, () => _asyncUow.Value);
|
||||
#endregion
|
||||
|
||||
fsql.Aop.ParseExpression += (_, e) =>
|
||||
{
|
||||
if (e.Expression is MemberExpression memExp == false) return;
|
||||
ParameterExpression parmExp = null;
|
||||
var exps = new List<MemberExpression>();
|
||||
exps.Add(memExp);
|
||||
while (memExp.Expression != null)
|
||||
{
|
||||
if (memExp.Expression is MemberExpression parentExp)
|
||||
{
|
||||
exps.Add(parentExp);
|
||||
memExp = parentExp;
|
||||
if (fsql.CodeFirst.GetTableByEntity(memExp.Type) == null) return;
|
||||
continue;
|
||||
}
|
||||
if (memExp.Expression is ParameterExpression parmExp2)
|
||||
{
|
||||
parmExp = parmExp2;
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (parmExp == null) return;
|
||||
var oldTables = e.Tables.ToArray();
|
||||
var result = e.FreeParse(e.Expression);
|
||||
for (var a = oldTables.Length; a < e.Tables.Count; a++)
|
||||
{
|
||||
if (string.IsNullOrEmpty(e.Tables[a].NavigateCondition) == false) continue;
|
||||
var parentTableAlias = e.Tables[a].Alias?.Split(new[] { "__" }, StringSplitOptions.None);
|
||||
if (parentTableAlias == null || parentTableAlias.Length <= 1) continue;
|
||||
var parentTable = e.Tables.Where(c => c.Alias == string.Join("__", parentTableAlias.Take(parentTableAlias.Length - 1))).FirstOrDefault();
|
||||
if (parentTable == null || parentTable.Table.Properties.TryGetValue(parentTableAlias.Last(), out var navProp) == false) continue;
|
||||
var joinAttr = navProp.GetCustomAttribute<JoinConditionAttribute>();
|
||||
if (joinAttr == null) continue;
|
||||
e.Tables[a].NavigateCondition = joinAttr.Condition
|
||||
.Replace("a.", e.Tables[a].Alias + ".")
|
||||
.Replace("b.", parentTable.Alias + ".");
|
||||
}
|
||||
e.Result = result;
|
||||
};
|
||||
var joinsql1 = fsql.Select<JoinTest01>()
|
||||
.Include(a => a.Parent.Parent)
|
||||
.Where(a => a.Parent.Parent.code == "001")
|
||||
.ToSql();
|
||||
|
||||
|
||||
fsql.Aop.ConfigEntity += (_, e) =>
|
||||
{
|
||||
Console.WriteLine("Aop.ConfigEntity: " + e.ModifyResult.Name);
|
||||
|
@ -733,6 +733,15 @@
|
||||
<param name="modelBuilder"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSqlDbContextExtensions.ApplyConfigurationsFromAssembly(FreeSql.ICodeFirst,System.Reflection.Assembly,System.Func{System.Type,System.Boolean})">
|
||||
<summary>
|
||||
根据Assembly扫描所有继承IEntityTypeConfiguration<T>的配置类
|
||||
</summary>
|
||||
<param name="codeFirst"></param>
|
||||
<param name="assembly"></param>
|
||||
<param name="predicate"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:FreeSqlDbContextExtensions.CreateDbContext(IFreeSql)">
|
||||
<summary>
|
||||
创建普通数据上下文档对象
|
||||
@ -791,5 +800,14 @@
|
||||
<param name="that"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Microsoft.Extensions.DependencyInjection.FreeSqlRepositoryDependencyInjection.AddFreeRepository(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{FreeSql.FluentDataFilter},System.Reflection.Assembly[])">
|
||||
<summary>
|
||||
批量注入 Repository,可以参考代码自行调整
|
||||
</summary>
|
||||
<param name="services"></param>
|
||||
<param name="globalDataFilter"></param>
|
||||
<param name="assemblies"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
|
@ -6,7 +6,6 @@ using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -1017,9 +1016,15 @@ namespace FreeSql.Internal.CommonProvider
|
||||
|
||||
if (_source.Any() == false)
|
||||
{
|
||||
var sbString = "";
|
||||
foreach (var col in _table.Columns.Values)
|
||||
if (col.Attribute.CanUpdate && string.IsNullOrEmpty(col.DbUpdateValue) == false)
|
||||
sb.Append(", ").Append(_commonUtils.QuoteSqlName(col.Attribute.Name)).Append(" = ").Append(col.DbUpdateValue);
|
||||
{
|
||||
if (sbString == "") sbString = sb.ToString();
|
||||
var loc3 = _commonUtils.QuoteSqlName(col.Attribute.Name);
|
||||
if (sbString.Contains(loc3)) continue;
|
||||
sb.Append(", ").Append(loc3).Append(" = ").Append(col.DbUpdateValue);
|
||||
}
|
||||
}
|
||||
|
||||
if (_versionColumn != null)
|
||||
|
@ -193,9 +193,15 @@ namespace FreeSql.ClickHouse.Curd
|
||||
|
||||
if (_source.Any() == false)
|
||||
{
|
||||
var sbString = "";
|
||||
foreach (var col in _table.Columns.Values)
|
||||
if (col.Attribute.CanUpdate && string.IsNullOrEmpty(col.DbUpdateValue) == false)
|
||||
sb.Append(", ").Append(_commonUtils.QuoteSqlName(col.Attribute.Name)).Append(" = ").Append(col.DbUpdateValue);
|
||||
{
|
||||
if (sbString == "") sbString = sb.ToString();
|
||||
var loc3 = _commonUtils.QuoteSqlName(col.Attribute.Name);
|
||||
if (sbString.Contains(loc3)) continue;
|
||||
sb.Append(", ").Append(loc3).Append(" = ").Append(col.DbUpdateValue);
|
||||
}
|
||||
}
|
||||
|
||||
if (_table.VersionColumn != null)
|
||||
|
Loading…
x
Reference in New Issue
Block a user