using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Threading.Tasks; namespace SqlSugar { public class UpdateNavTaskInit where T : class, new() where Root : class, new() { internal SqlSugarProvider Context { get; set; } internal UpdateNavProvider UpdateNavProvider { get; set; } internal NavContext NavContext { get; set; } public UpdateNavTask Include(Expression> expression) where TChild : class, new() { this.Context = UpdateNavProvider._Context; UpdateNavProvider.NavContext = this.NavContext; UpdateNavTask result = new UpdateNavTask(); Func> func = () => UpdateNavProvider.ThenInclude(expression); result.PreFunc = func; result.Context = this.Context; result.NavContext = this.NavContext; return result; } public UpdateNavTask Include(Expression>> expression) where TChild : class, new() { this.Context = UpdateNavProvider._Context; UpdateNavProvider.NavContext = this.NavContext; UpdateNavTask result = new UpdateNavTask(); Func> func = () => UpdateNavProvider.ThenInclude(expression); result.PreFunc = func; result.Context = this.Context; result.NavContext = UpdateNavProvider.NavContext; return result; } public UpdateNavTask Include(Expression> expression,UpdateNavOptions options) where TChild : class, new() { this.Context = UpdateNavProvider._Context; UpdateNavProvider.NavContext = this.NavContext; UpdateNavTask result = new UpdateNavTask(); Func> func = () => UpdateNavProvider.ThenInclude(expression,options); result.PreFunc = func; result.Context = this.Context; result.NavContext = UpdateNavProvider.NavContext; return result; } public UpdateNavTask Include(Expression>> expression, UpdateNavOptions options) where TChild : class, new() { this.Context = UpdateNavProvider._Context; UpdateNavProvider.NavContext = this.NavContext; UpdateNavTask result = new UpdateNavTask(); Func> func = () => UpdateNavProvider.ThenInclude(expression,options); result.PreFunc = func; result.Context = this.Context; result.NavContext = UpdateNavProvider.NavContext; return result; } } public class UpdateNavTask where T : class, new() where Root : class, new() { public SqlSugarProvider Context { get; set; } public Func> PreFunc { get; set; } internal NavContext NavContext { get; set; } #region +1 public UpdateNavTask ThenInclude(Expression> expression) where TChild : class, new() { UpdateNavTask result = new UpdateNavTask(); Func> func = () => PreFunc().ThenInclude(expression); result.PreFunc = func; result.Context = this.Context; result.NavContext = this.NavContext; return result; } public UpdateNavTask ThenInclude(Expression>> expression) where TChild : class, new() { UpdateNavTask result = new UpdateNavTask(); Func> func = () => PreFunc().ThenInclude(expression); result.PreFunc = func; result.Context = this.Context; result.NavContext = this.NavContext; return result; } public UpdateNavTask Include(Expression> expression) where TChild : class, new() { return AsNav().ThenInclude(expression); } public UpdateNavTask Include(Expression>> expression) where TChild : class, new() { return AsNav().ThenInclude(expression); } #endregion #region +2 public UpdateNavTask ThenInclude(Expression> expression, UpdateNavOptions options) where TChild : class, new() { UpdateNavTask result = new UpdateNavTask(); Func> func = () => { var nav = PreFunc().ThenInclude(expression, options); nav.NavContext = this.NavContext; return nav; }; result.PreFunc = func; result.Context = this.Context; return result; } public UpdateNavTask ThenInclude(Expression>> expression, UpdateNavOptions options) where TChild : class, new() { UpdateNavTask result = new UpdateNavTask(); Func> func = () => { var nav = PreFunc().ThenInclude(expression, options); result.NavContext = this.NavContext; return nav; }; result.PreFunc = func; result.Context = this.Context; return result; } public UpdateNavTask Include(Expression> expression, UpdateNavOptions options) where TChild : class, new() { return AsNav().ThenInclude(expression, options); } public UpdateNavTask Include(Expression>> expression, UpdateNavOptions options) where TChild : class, new() { return AsNav().ThenInclude(expression, options); } #endregion public bool ExecuteCommand() { var hasTran = this.Context.Ado.Transaction != null; if (hasTran) { PreFunc(); } else { this.Context.Ado.UseTran(() => { PreFunc(); }, ex => throw ex); } return true; } public async Task ExecuteCommandAsync() { await Task.Run(async () => { ExecuteCommand(); await Task.Delay(0); }); return true; } private UpdateNavTask AsNav() { UpdateNavTask result = new UpdateNavTask(); Func> func = () => { var navres=PreFunc().AsNav(); navres.IsAsNav = true; navres.NavContext = this.NavContext; return navres; }; result.PreFunc = func; result.Context = this.Context; result.NavContext = this.NavContext; return result; } } }