diff --git a/AmalgamationTool/DynamORM.Amalgamation.cs b/AmalgamationTool/DynamORM.Amalgamation.cs
index e9ebcd5..7fb9fe2 100644
--- a/AmalgamationTool/DynamORM.Amalgamation.cs
+++ b/AmalgamationTool/DynamORM.Amalgamation.cs
@@ -2,31 +2,6 @@
* DynamORM - Dynamic Object-Relational Mapping library.
* Copyright (c) 2012-2026, Grzegorz Russek (grzegorz.russek@gmail.com)
* All rights reserved.
- *
- * Some of methods in this code file is based on Kerosene ORM solution
- * for parsing dynamic lambda expressions by Moisés Barba Cebeira
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
*/
using DynamORM.Builders.Extensions;
@@ -35,6 +10,7 @@ using DynamORM.Builders;
using DynamORM.Helpers.Dynamics;
using DynamORM.Helpers;
using DynamORM.Mapper;
+using DynamORM.TypedSql;
using DynamORM.Validation;
using System.Collections.Concurrent;
using System.Collections.Generic;
@@ -1976,6 +1952,43 @@ namespace DynamORM
}
}
/// Adds to the FROM clause using .
+ /// Type which can be represented in database.
+ /// Table alias.
+ /// use no lock.
+ /// This instance to permit chaining.
+ public virtual IDynamicTypedSelectQueryBuilder FromTyped(string alias = null, bool noLock = false)
+ {
+ // TODO: Make it more readable and maitainable
+ DynamicTypedSelectQueryBuilder builder = new DynamicTypedSelectQueryBuilder(this);
+
+ if (noLock)
+ {
+ if (string.IsNullOrEmpty(alias))
+ builder.From(x => x(typeof(T)).NoLock());
+ else
+ builder.From(x => x(typeof(T)).As(alias).NoLock());
+ }
+ else
+ {
+ if (string.IsNullOrEmpty(alias))
+ builder.From(x => x(typeof(T)));
+ else
+ builder.From(x => x(typeof(T)).As(alias));
+ }
+ 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.
public virtual IDynamicSelectQueryBuilder From(Type t)
@@ -2005,6 +2018,13 @@ namespace DynamORM
return new DynamicInsertQueryBuilder(this).Table(typeof(T));
}
/// Adds to the INSERT INTO clause using .
+ /// Type which can be represented in database.
+ /// This instance to permit chaining.
+ public virtual IDynamicTypedInsertQueryBuilder InsertTyped()
+ {
+ return new DynamicTypedInsertQueryBuilder(this, true);
+ }
+ /// Adds to the INSERT INTO clause using .
/// Type which can be represented in database.
/// This instance to permit chaining.
public virtual IDynamicInsertQueryBuilder Insert(Type t)
@@ -2105,6 +2125,13 @@ namespace DynamORM
return new DynamicUpdateQueryBuilder(this).Table(typeof(T));
}
/// Adds to the UPDATE clause using .
+ /// Type which can be represented in database.
+ /// This instance to permit chaining.
+ public virtual IDynamicTypedUpdateQueryBuilder UpdateTyped()
+ {
+ return new DynamicTypedUpdateQueryBuilder(this, true);
+ }
+ /// Adds to the UPDATE clause using .
/// Type which can be represented in database.
/// This instance to permit chaining.
public virtual IDynamicUpdateQueryBuilder Update(Type t)
@@ -2314,6 +2341,13 @@ namespace DynamORM
return new DynamicDeleteQueryBuilder(this).Table(typeof(T));
}
/// Adds to the DELETE FROM clause using .
+ /// Type which can be represented in database.
+ /// This instance to permit chaining.
+ public virtual IDynamicTypedDeleteQueryBuilder DeleteTyped()
+ {
+ return new DynamicTypedDeleteQueryBuilder(this, true);
+ }
+ /// Adds to the DELETE FROM clause using .
/// Type which can be represented in database.
/// This instance to permit chaining.
public virtual IDynamicDeleteQueryBuilder Delete(Type t)
@@ -6794,6 +6828,18 @@ namespace DynamORM
}
namespace Builders
{
+ /// Typed join kind used by typed fluent builder APIs.
+ public enum DynamicJoinType
+ {
+ Inner = 0,
+ Join,
+ Left,
+ Right,
+ Full,
+ LeftOuter,
+ RightOuter,
+ FullOuter
+ }
/// Dynamic delete query builder interface.
/// This interface it publicly available. Implementation should be hidden.
public interface IDynamicDeleteQueryBuilder : IDynamicQueryBuilder
@@ -7161,6 +7207,347 @@ namespace DynamORM
#endregion Top/Limit/Offset/Distinct
}
+ /// Typed delete query builder for mapped entities.
+ /// Mapped entity type.
+ public interface IDynamicTypedDeleteQueryBuilder : IDynamicDeleteQueryBuilder
+ {
+ /// Add typed where predicate using mapped properties.
+ /// Predicate to parse.
+ /// Builder instance.
+ IDynamicTypedDeleteQueryBuilder Where(Expression> predicate);
+
+ /// Add typed SQL DSL where predicate.
+ IDynamicTypedDeleteQueryBuilder WhereSql(Func, TypedSqlPredicate> predicate);
+ }
+ /// Typed insert query builder for mapped entities.
+ /// Mapped entity type.
+ public interface IDynamicTypedInsertQueryBuilder : IDynamicInsertQueryBuilder
+ {
+ /// Add typed insert assignment using mapped property selector.
+ /// Property type.
+ /// Property selector.
+ /// Value to insert.
+ /// Builder instance.
+ IDynamicTypedInsertQueryBuilder Insert(Expression> selector, object value);
+
+ /// Add values from mapped object.
+ /// Mapped object value.
+ /// Builder instance.
+ IDynamicTypedInsertQueryBuilder Insert(T value);
+
+ /// Add typed SQL DSL insert assignment.
+ IDynamicTypedInsertQueryBuilder InsertSql(Expression> selector, Func, TypedSqlExpression> valueFactory);
+
+ /// Add typed SQL DSL insert assignments from object projection.
+ IDynamicTypedInsertQueryBuilder InsertSql(Func, object> values);
+ }
+ /// Typed select query builder for mapped entities.
+ /// Mapped entity type.
+ public interface IDynamicTypedSelectQueryBuilder : IDynamicSelectQueryBuilder
+ {
+ /// Add typed join to mapped table.
+ /// Joined mapped entity type.
+ /// Join ON predicate.
+ /// Optional alias for joined table.
+ /// Join type.
+ /// Adds NOLOCK hint to joined source when supported by provider options.
+ /// Builder instance.
+ IDynamicTypedSelectQueryBuilder Join(Expression> on, string alias = null, DynamicJoinType joinType = DynamicJoinType.Inner, bool noLock = false);
+
+ /// Add typed join with custom join type text (for example: CROSS APPLY).
+ /// Joined mapped entity type.
+ /// Optional join ON predicate.
+ /// Optional alias for joined table.
+ /// Join type text.
+ /// Adds NOLOCK hint to joined source when supported by provider options.
+ /// Builder instance.
+ IDynamicTypedSelectQueryBuilder Join(Expression> on, string alias, string joinType, bool noLock = false);
+
+ /// Add typed join using join-spec builder syntax (As(), join kind and On()).
+ /// Joined mapped entity type.
+ /// Join specification builder callback.
+ /// Builder instance.
+ IDynamicTypedSelectQueryBuilder Join(Func, TypedJoinBuilder> specification);
+
+ /// Add typed where predicate using mapped properties.
+ /// Predicate to parse.
+ /// Builder instance.
+ IDynamicTypedSelectQueryBuilder Where(Expression> predicate);
+
+ /// Add typed having predicate using mapped properties.
+ /// Predicate to parse.
+ /// Builder instance.
+ IDynamicTypedSelectQueryBuilder Having(Expression> predicate);
+
+ /// Add typed selected columns using mapped properties.
+ /// Projection type.
+ /// Selector to parse.
+ /// Additional selectors to parse.
+ /// Builder instance.
+ IDynamicTypedSelectQueryBuilder Select(Expression> selector, params Expression>[] selectors);
+
+ /// Add typed group by columns using mapped properties.
+ /// Projection type.
+ /// Selector to parse.
+ /// Additional selectors to parse.
+ /// Builder instance.
+ IDynamicTypedSelectQueryBuilder GroupBy(Expression> selector, params Expression>[] selectors);
+
+ /// Add typed order by columns using mapped properties. Supports Asc()/Desc().
+ /// Projection type.
+ /// Selector to parse.
+ /// Additional selectors to parse.
+ /// Builder instance.
+ IDynamicTypedSelectQueryBuilder OrderBy(Expression> selector, params Expression>[] selectors);
+
+ /// Add typed SQL DSL select items.
+ IDynamicTypedSelectQueryBuilder SelectSql(Func, TypedSqlSelectable> selector, params Func, TypedSqlSelectable>[] selectors);
+
+ /// Add typed SQL DSL where predicate.
+ IDynamicTypedSelectQueryBuilder WhereSql(Func, TypedSqlPredicate> predicate);
+
+ /// Add typed SQL DSL having predicate.
+ IDynamicTypedSelectQueryBuilder HavingSql(Func, TypedSqlPredicate> predicate);
+
+ /// Add typed SQL DSL group by expressions.
+ IDynamicTypedSelectQueryBuilder GroupBySql(Func, TypedSqlExpression> selector, params Func, TypedSqlExpression>[] selectors);
+
+ /// Add typed SQL DSL order by expressions.
+ IDynamicTypedSelectQueryBuilder OrderBySql(Func, TypedSqlOrderExpression> selector, params Func, TypedSqlOrderExpression>[] selectors);
+
+ /// Add typed SQL DSL select items using root and first joined table contexts.
+ IDynamicTypedSelectQueryBuilder SelectSql(Func, TypedTableContext, TypedSqlSelectable> selector, params Func, TypedTableContext, TypedSqlSelectable>[] selectors);
+
+ /// Add typed SQL DSL select items using root and first two joined table contexts.
+ IDynamicTypedSelectQueryBuilder SelectSql(Func, TypedTableContext, TypedTableContext, TypedSqlSelectable> selector, params Func, TypedTableContext, TypedTableContext, TypedSqlSelectable>[] selectors);
+
+ /// Add typed SQL DSL select items using root and first three joined table contexts.
+ IDynamicTypedSelectQueryBuilder SelectSql(Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlSelectable> selector, params Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlSelectable>[] selectors);
+
+ /// Add typed SQL DSL select items using root and first four joined table contexts.
+ IDynamicTypedSelectQueryBuilder SelectSql(Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlSelectable> selector, params Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlSelectable>[] selectors);
+
+ /// Add typed SQL DSL where predicate using root and first joined table contexts.
+ IDynamicTypedSelectQueryBuilder WhereSql(Func, TypedTableContext, TypedSqlPredicate> predicate);
+
+ /// Add typed SQL DSL where predicate using root and first two joined table contexts.
+ IDynamicTypedSelectQueryBuilder WhereSql(Func, TypedTableContext, TypedTableContext, TypedSqlPredicate> predicate);
+
+ /// Add typed SQL DSL where predicate using root and first three joined table contexts.
+ IDynamicTypedSelectQueryBuilder WhereSql(Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlPredicate> predicate);
+
+ /// Add typed SQL DSL where predicate using root and first four joined table contexts.
+ IDynamicTypedSelectQueryBuilder WhereSql(Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlPredicate> predicate);
+
+ /// Add typed SQL DSL having predicate using root and first joined table contexts.
+ IDynamicTypedSelectQueryBuilder HavingSql(Func, TypedTableContext, TypedSqlPredicate> predicate);
+
+ /// Add typed SQL DSL having predicate using root and first two joined table contexts.
+ IDynamicTypedSelectQueryBuilder HavingSql(Func, TypedTableContext, TypedTableContext, TypedSqlPredicate> predicate);
+
+ /// Add typed SQL DSL having predicate using root and first three joined table contexts.
+ IDynamicTypedSelectQueryBuilder HavingSql(Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlPredicate> predicate);
+
+ /// Add typed SQL DSL having predicate using root and first four joined table contexts.
+ IDynamicTypedSelectQueryBuilder HavingSql(Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlPredicate> predicate);
+
+ /// Add typed SQL DSL group-by expression using root and first joined table contexts.
+ IDynamicTypedSelectQueryBuilder GroupBySql(Func, TypedTableContext, TypedSqlExpression> selector, params Func, TypedTableContext, TypedSqlExpression>[] selectors);
+
+ /// Add typed SQL DSL group-by expression using root and first two joined table contexts.
+ IDynamicTypedSelectQueryBuilder GroupBySql(Func, TypedTableContext, TypedTableContext, TypedSqlExpression> selector, params Func, TypedTableContext, TypedTableContext, TypedSqlExpression>[] selectors);
+
+ /// Add typed SQL DSL group-by expression using root and first three joined table contexts.
+ IDynamicTypedSelectQueryBuilder GroupBySql(Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlExpression> selector, params Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlExpression>[] selectors);
+
+ /// Add typed SQL DSL group-by expression using root and first four joined table contexts.
+ IDynamicTypedSelectQueryBuilder GroupBySql(Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlExpression> selector, params Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlExpression>[] selectors);
+
+ /// Add typed SQL DSL order-by expression using root and first joined table contexts.
+ IDynamicTypedSelectQueryBuilder OrderBySql(Func, TypedTableContext, TypedSqlOrderExpression> selector, params Func, TypedTableContext, TypedSqlOrderExpression>[] selectors);
+
+ /// Add typed SQL DSL order-by expression using root and first two joined table contexts.
+ IDynamicTypedSelectQueryBuilder OrderBySql(Func, TypedTableContext, TypedTableContext, TypedSqlOrderExpression> selector, params Func, TypedTableContext, TypedTableContext, TypedSqlOrderExpression>[] selectors);
+
+ /// Add typed SQL DSL order-by expression using root and first three joined table contexts.
+ IDynamicTypedSelectQueryBuilder OrderBySql(Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlOrderExpression> selector, params Func, TypedTableContext, TypedTableContext, TypedTableContext, TypedSqlOrderExpression>[] selectors);
+
+ /// 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);
+ }
+ 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);
+ }
+ public interface IDynamicTypedSelectScopeQueryBuilder : IDynamicSelectQueryBuilder
+ {
+ IDynamicTypedSelectScopeQueryBuilder Join(Func, TypedScopeJoinBuilder> specification);
+ IDynamicTypedSelectScopeQueryBuilder SelectSql(Func, TypedTableContext, TypedSqlSelectable> selector, params Func, TypedTableContext