diff --git a/AmalgamationTool/DynamORM.Amalgamation.cs b/AmalgamationTool/DynamORM.Amalgamation.cs
index 7762576..51e5c7c 100644
--- a/AmalgamationTool/DynamORM.Amalgamation.cs
+++ b/AmalgamationTool/DynamORM.Amalgamation.cs
@@ -1977,6 +1977,17 @@ namespace DynamORM
}
return builder;
}
+ /// Adds to the FROM clause using a typed scope builder with evolving join arity.
+ /// Type which can be represented in database.
+ /// Table alias.
+ /// use no lock.
+ /// Scope builder instance.
+ public virtual IDynamicTypedSelectScopeQueryBuilder FromTypedScope(string alias = null, bool noLock = false)
+ {
+ DynamicTypedSelectQueryBuilder builder = (DynamicTypedSelectQueryBuilder)FromTyped(alias, noLock);
+ string resolvedAlias = string.IsNullOrEmpty(alias) ? builder.Tables[0].Alias ?? builder.Tables[0].Name : alias;
+ return new DynamicTypedSelectScopeQueryBuilder(builder, resolvedAlias);
+ }
/// Adds to the FROM clause using .
/// Type which can be represented in database.
/// This instance to permit chaining.
@@ -7364,6 +7375,55 @@ namespace DynamORM
/// Add typed SQL DSL order-by expression using root and first four joined table contexts.
IDynamicTypedSelectQueryBuilder OrderBySql(Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlOrderExpression> selector, params Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlOrderExpression>[] selectors);
}
+ /// Typed scope-based select builder with evolving join arity.
+ public interface IDynamicTypedSelectScopeQueryBuilder : IDynamicSelectQueryBuilder
+ {
+ IDynamicTypedSelectScopeQueryBuilder Join(Func, TypedScopeJoinBuilder> specification);
+ IDynamicTypedSelectScopeQueryBuilder SelectSql(Func, TypedSqlSelectable> selector, params Func, TypedSqlSelectable>[] selectors);
+ IDynamicTypedSelectScopeQueryBuilder WhereSql(Func, TypedSqlPredicate> predicate);
+ IDynamicTypedSelectScopeQueryBuilder HavingSql(Func, TypedSqlPredicate> predicate);
+ IDynamicTypedSelectScopeQueryBuilder GroupBySql(Func, TypedSqlExpression> selector, params Func, TypedSqlExpression>[] selectors);
+ IDynamicTypedSelectScopeQueryBuilder OrderBySql(Func, TypedSqlOrderExpression> selector, params Func, TypedSqlOrderExpression>[] selectors);
+ }
+ /// Typed scope-based select builder with two typed table contexts.
+ public interface IDynamicTypedSelectScopeQueryBuilder : IDynamicSelectQueryBuilder
+ {
+ IDynamicTypedSelectScopeQueryBuilder Join(Func, TypedScopeJoinBuilder> specification);
+ IDynamicTypedSelectScopeQueryBuilder SelectSql(Func, TypedTableContext, TypedSqlSelectable> selector, params Func, TypedTableContext, TypedSqlSelectable>[] selectors);
+ IDynamicTypedSelectScopeQueryBuilder WhereSql(Func, TypedTableContext, TypedSqlPredicate> predicate);
+ IDynamicTypedSelectScopeQueryBuilder HavingSql(Func, TypedTableContext, TypedSqlPredicate> predicate);
+ IDynamicTypedSelectScopeQueryBuilder GroupBySql(Func, TypedTableContext, TypedSqlExpression> selector, params Func, TypedTableContext, TypedSqlExpression>[] selectors);
+ IDynamicTypedSelectScopeQueryBuilder OrderBySql(Func, TypedTableContext, TypedSqlOrderExpression> selector, params Func, TypedTableContext, TypedSqlOrderExpression>[] selectors);
+ }
+ /// Typed scope-based select builder with three typed table contexts.
+ public interface IDynamicTypedSelectScopeQueryBuilder : IDynamicSelectQueryBuilder
+ {
+ IDynamicTypedSelectScopeQueryBuilder Join(Func, TypedScopeJoinBuilder> specification);
+ IDynamicTypedSelectScopeQueryBuilder SelectSql(Func, TypedTableContext, TypedTableContext, TypedSqlSelectable> selector, params Func, TypedTableContext, TypedTableContext, TypedSqlSelectable>[] selectors);
+ IDynamicTypedSelectScopeQueryBuilder WhereSql(Func, TypedTableContext, TypedTableContext, TypedSqlPredicate> predicate);
+ IDynamicTypedSelectScopeQueryBuilder HavingSql(Func, TypedTableContext, TypedTableContext, TypedSqlPredicate> predicate);
+ IDynamicTypedSelectScopeQueryBuilder GroupBySql(Func, TypedTableContext, TypedTableContext, TypedSqlExpression> selector, params Func, TypedTableContext, TypedTableContext, TypedSqlExpression>[] selectors);
+ IDynamicTypedSelectScopeQueryBuilder OrderBySql(Func, TypedTableContext, TypedTableContext, TypedSqlOrderExpression> selector, params Func, TypedTableContext, TypedTableContext, TypedSqlOrderExpression>[] selectors);
+ }
+ /// Typed scope-based select builder with four typed table contexts.
+ public interface IDynamicTypedSelectScopeQueryBuilder : IDynamicSelectQueryBuilder
+ {
+ IDynamicTypedSelectScopeQueryBuilder Join(Func, TypedScopeJoinBuilder> specification);
+ IDynamicTypedSelectScopeQueryBuilder SelectSql(Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlSelectable> selector, params Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlSelectable>[] selectors);
+ IDynamicTypedSelectScopeQueryBuilder WhereSql(Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlPredicate> predicate);
+ IDynamicTypedSelectScopeQueryBuilder HavingSql(Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlPredicate> predicate);
+ IDynamicTypedSelectScopeQueryBuilder GroupBySql(Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlExpression> selector, params Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlExpression>[] selectors);
+ IDynamicTypedSelectScopeQueryBuilder OrderBySql(Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlOrderExpression> selector, params Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlOrderExpression>[] selectors);
+ }
+ /// Typed scope-based select builder with five typed table contexts.
+ public interface IDynamicTypedSelectScopeQueryBuilder : IDynamicSelectQueryBuilder
+ {
+ IDynamicTypedSelectScopeQueryBuilder SelectSql(Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlSelectable> selector, params Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlSelectable>[] selectors);
+ IDynamicTypedSelectScopeQueryBuilder WhereSql(Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlPredicate> predicate);
+ IDynamicTypedSelectScopeQueryBuilder HavingSql(Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlPredicate> predicate);
+ IDynamicTypedSelectScopeQueryBuilder GroupBySql(Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlExpression> selector, params Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlExpression>[] selectors);
+ IDynamicTypedSelectScopeQueryBuilder OrderBySql(Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlOrderExpression> selector, params Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlOrderExpression>[] selectors);
+ }
/// Typed update query builder for mapped entities.
/// Mapped entity type.
public interface IDynamicTypedUpdateQueryBuilder : IDynamicUpdateQueryBuilder
@@ -7753,6 +7813,188 @@ namespace DynamORM
return builder.Join(on, alias, DynamicJoinType.Full);
}
}
+ public abstract class TypedScopeJoinBuilderBase
+ where TSelf : TypedScopeJoinBuilderBase
+ {
+ /// Gets join alias.
+ public string Alias { get; private set; }
+
+ /// Gets join type.
+ public DynamicJoinType JoinType { get; private set; }
+
+ /// Gets custom join type text.
+ public string CustomJoinType { get; private set; }
+
+ /// Gets a value indicating whether joined source should use NOLOCK.
+ public bool UseNoLock { get; private set; }
+
+ protected TypedScopeJoinBuilderBase()
+ {
+ JoinType = DynamicJoinType.Join;
+ }
+ public TSelf As(string alias)
+ {
+ Alias = alias;
+ return (TSelf)this;
+ }
+ public TSelf Inner()
+ {
+ JoinType = DynamicJoinType.Inner;
+ CustomJoinType = null;
+ return (TSelf)this;
+ }
+ public TSelf Join()
+ {
+ JoinType = DynamicJoinType.Join;
+ CustomJoinType = null;
+ return (TSelf)this;
+ }
+ public TSelf Left()
+ {
+ JoinType = DynamicJoinType.Left;
+ CustomJoinType = null;
+ return (TSelf)this;
+ }
+ public TSelf Right()
+ {
+ JoinType = DynamicJoinType.Right;
+ CustomJoinType = null;
+ return (TSelf)this;
+ }
+ public TSelf Full()
+ {
+ JoinType = DynamicJoinType.Full;
+ CustomJoinType = null;
+ return (TSelf)this;
+ }
+ public TSelf LeftOuter()
+ {
+ JoinType = DynamicJoinType.LeftOuter;
+ CustomJoinType = null;
+ return (TSelf)this;
+ }
+ public TSelf RightOuter()
+ {
+ JoinType = DynamicJoinType.RightOuter;
+ CustomJoinType = null;
+ return (TSelf)this;
+ }
+ public TSelf FullOuter()
+ {
+ JoinType = DynamicJoinType.FullOuter;
+ CustomJoinType = null;
+ return (TSelf)this;
+ }
+ public TSelf Type(string joinType)
+ {
+ if (string.IsNullOrEmpty(joinType))
+ throw new ArgumentNullException("joinType");
+
+ CustomJoinType = joinType.Trim();
+ return (TSelf)this;
+ }
+ public TSelf NoLock(bool use = true)
+ {
+ UseNoLock = use;
+ return (TSelf)this;
+ }
+ }
+ public sealed class TypedScopeJoinBuilder : TypedScopeJoinBuilderBase>
+ {
+ internal Func, TypedTableContext, TypedSqlPredicate> OnSqlPredicate { get; private set; }
+ internal string OnRawCondition { get; private set; }
+
+ public TypedScopeJoinBuilder OnSql(Func, TypedTableContext, TypedSqlPredicate> predicate)
+ {
+ if (predicate == null)
+ throw new ArgumentNullException("predicate");
+
+ OnSqlPredicate = predicate;
+ OnRawCondition = null;
+ return this;
+ }
+ public TypedScopeJoinBuilder OnRaw(string condition)
+ {
+ if (string.IsNullOrEmpty(condition))
+ throw new ArgumentNullException("condition");
+
+ OnRawCondition = condition.Trim();
+ OnSqlPredicate = null;
+ return this;
+ }
+ }
+ public sealed class TypedScopeJoinBuilder : TypedScopeJoinBuilderBase>
+ {
+ internal Func, TypedTableContext, TypedTableContext, TypedSqlPredicate> OnSqlPredicate { get; private set; }
+ internal string OnRawCondition { get; private set; }
+
+ public TypedScopeJoinBuilder OnSql(Func, TypedTableContext, TypedTableContext, TypedSqlPredicate> predicate)
+ {
+ if (predicate == null)
+ throw new ArgumentNullException("predicate");
+
+ OnSqlPredicate = predicate;
+ OnRawCondition = null;
+ return this;
+ }
+ public TypedScopeJoinBuilder OnRaw(string condition)
+ {
+ if (string.IsNullOrEmpty(condition))
+ throw new ArgumentNullException("condition");
+
+ OnRawCondition = condition.Trim();
+ OnSqlPredicate = null;
+ return this;
+ }
+ }
+ public sealed class TypedScopeJoinBuilder : TypedScopeJoinBuilderBase>
+ {
+ internal Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlPredicate> OnSqlPredicate { get; private set; }
+ internal string OnRawCondition { get; private set; }
+
+ public TypedScopeJoinBuilder OnSql(Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlPredicate> predicate)
+ {
+ if (predicate == null)
+ throw new ArgumentNullException("predicate");
+
+ OnSqlPredicate = predicate;
+ OnRawCondition = null;
+ return this;
+ }
+ public TypedScopeJoinBuilder OnRaw(string condition)
+ {
+ if (string.IsNullOrEmpty(condition))
+ throw new ArgumentNullException("condition");
+
+ OnRawCondition = condition.Trim();
+ OnSqlPredicate = null;
+ return this;
+ }
+ }
+ public sealed class TypedScopeJoinBuilder : TypedScopeJoinBuilderBase>
+ {
+ internal Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlPredicate> OnSqlPredicate { get; private set; }
+ internal string OnRawCondition { get; private set; }
+
+ public TypedScopeJoinBuilder OnSql(Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlPredicate> predicate)
+ {
+ if (predicate == null)
+ throw new ArgumentNullException("predicate");
+
+ OnSqlPredicate = predicate;
+ OnRawCondition = null;
+ return this;
+ }
+ public TypedScopeJoinBuilder OnRaw(string condition)
+ {
+ if (string.IsNullOrEmpty(condition))
+ throw new ArgumentNullException("condition");
+
+ OnRawCondition = condition.Trim();
+ OnSqlPredicate = null;
+ return this;
+ }
+ }
namespace Extensions
{
internal static class DynamicHavingQueryExtensions
@@ -11589,6 +11831,10 @@ namespace DynamORM
TypedSqlRenderContext context = new TypedSqlRenderContext(this);
return predicate.Render(context);
}
+ internal string RenderScopeSqlPredicate(TypedSqlPredicate predicate)
+ {
+ return RenderSqlPredicate(predicate);
+ }
private string ParseTypedCondition(Expression expression)
{
expression = UnwrapConvert(expression);
@@ -11981,6 +12227,475 @@ namespace DynamORM
return getter();
}
}
+ internal abstract class DynamicTypedSelectScopeQueryBuilderBase : IDynamicSelectQueryBuilder
+ {
+ protected readonly DynamicTypedSelectQueryBuilder Builder;
+
+ protected DynamicTypedSelectScopeQueryBuilderBase(DynamicTypedSelectQueryBuilder builder)
+ {
+ Builder = builder;
+ }
+ public DynamicDatabase Database { get { return Builder.Database; } }
+ public IList Tables { get { return Builder.Tables; } }
+ public IDictionary Parameters { get { return Builder.Parameters; } }
+ public bool VirtualMode { get { return Builder.VirtualMode; } set { Builder.VirtualMode = value; } }
+ public bool SupportSchema { get { return Builder.SupportSchema; } }
+ public List> OnCreateTemporaryParameter { get { return Builder.OnCreateTemporaryParameter; } set { Builder.OnCreateTemporaryParameter = value; } }
+ public List> OnCreateParameter { get { return Builder.OnCreateParameter; } set { Builder.OnCreateParameter = value; } }
+ public bool IsDisposed { get { return Builder.IsDisposed; } }
+
+ public void Dispose()
+ {
+ Builder.Dispose();
+ }
+ public IDbCommand FillCommand(IDbCommand command)
+ {
+ return Builder.FillCommand(command);
+ }
+ public string CommandText()
+ {
+ return Builder.CommandText();
+ }
+ public IEnumerable Execute()
+ {
+ return Builder.Execute();
+ }
+ public IEnumerable Execute() where T : class
+ {
+ return Builder.Execute();
+ }
+ public void ExecuteDataReader(Action reader)
+ {
+ Builder.ExecuteDataReader(reader);
+ }
+ public object Scalar()
+ {
+ return Builder.Scalar();
+ }
+ #if !DYNAMORM_OMMIT_GENERICEXECUTION && !DYNAMORM_OMMIT_TRYPARSE
+ public TResult ScalarAs(TResult defaultValue = default(TResult))
+ {
+ return Builder.ScalarAs(defaultValue);
+ }
+ #endif
+
+ public IDynamicSelectQueryBuilder From(Func fn, params Func[] func)
+ {
+ Builder.From(fn, func);
+ return this;
+ }
+ public IDynamicSelectQueryBuilder Join(params Func[] func)
+ {
+ Builder.Join(func);
+ return this;
+ }
+ public IDynamicSelectQueryBuilder Where(Func func)
+ {
+ Builder.Where(func);
+ return this;
+ }
+ public IDynamicSelectQueryBuilder Where(DynamicColumn column)
+ {
+ Builder.Where(column);
+ return this;
+ }
+ public IDynamicSelectQueryBuilder Where(string column, DynamicColumn.CompareOperator op, object value)
+ {
+ Builder.Where(column, op, value);
+ return this;
+ }
+ public IDynamicSelectQueryBuilder Where(string column, object value)
+ {
+ Builder.Where(column, value);
+ return this;
+ }
+ public IDynamicSelectQueryBuilder Where(object conditions, bool schema = false)
+ {
+ Builder.Where(conditions, schema);
+ return this;
+ }
+ public IDynamicSelectQueryBuilder Select(Func fn, params Func[] func)
+ {
+ Builder.Select(fn, func);
+ return this;
+ }
+ public IDynamicSelectQueryBuilder SelectColumn(params DynamicColumn[] columns)
+ {
+ Builder.SelectColumn(columns);
+ return this;
+ }
+ public IDynamicSelectQueryBuilder SelectColumn(params string[] columns)
+ {
+ Builder.SelectColumn(columns);
+ return this;
+ }
+ public IDynamicSelectQueryBuilder GroupBy(Func fn, params Func[] func)
+ {
+ Builder.GroupBy(fn, func);
+ return this;
+ }
+ public IDynamicSelectQueryBuilder GroupByColumn(params DynamicColumn[] columns)
+ {
+ Builder.GroupByColumn(columns);
+ return this;
+ }
+ public IDynamicSelectQueryBuilder GroupByColumn(params string[] columns)
+ {
+ Builder.GroupByColumn(columns);
+ return this;
+ }
+ public IDynamicSelectQueryBuilder Having(Func func)
+ {
+ Builder.Having(func);
+ return this;
+ }
+ public IDynamicSelectQueryBuilder Having(DynamicColumn column)
+ {
+ Builder.Having(column);
+ return this;
+ }
+ public IDynamicSelectQueryBuilder Having(string column, DynamicColumn.CompareOperator op, object value)
+ {
+ Builder.Having(column, op, value);
+ return this;
+ }
+ public IDynamicSelectQueryBuilder Having(string column, object value)
+ {
+ Builder.Having(column, value);
+ return this;
+ }
+ public IDynamicSelectQueryBuilder Having(object conditions, bool schema = false)
+ {
+ Builder.Having(conditions, schema);
+ return this;
+ }
+ public IDynamicSelectQueryBuilder OrderBy(Func fn, params Func