D3Specification Helper Class
The tool for creating D3Specification instances, prebuilding specifications, building SQL, removing extra filter or sort etc...
namespace KLO128.D3ORM.Common
{
public static class D3Specification
}
Assembly
KLO128.D3ORM.Common
Base Types
None
Properties
HelperInitialized
public static bool HelperInitialized { get; }
Description
Indicates if the SpecHelper is initialized.
SpecHelper
public static D3BaseSpecification? SpecHelper { private get; set; }
Description
DO NOT use externally. Internal static helper used to handle this tool functions. Instantiated with ID3Context instantiation.
ThrowWhenExpectedJoinNotSuccessful
public static bool ThrowWhenExpectedJoinNotSuccessful { get; } = true;
Description
Indicates if to throw an exception if a try of appending a join was not successful. True by default.
Methods
BuildSQL(..)
public static D3SQLAdapter BuildSQL(ISpecification that, bool useSkipAndTakeFormat, bool debugMode, IDictionary<int, object?> parameters)
Description
Builds and gets the SQL using the parameters for the filter.
parameters: Use null to omit the parameter at the specified order (placeholder index), use Convert.DBNull to compare it with database NULL. Do not use DbParameter or D3Parameter! Instead of that for the case of stored procedures, use D3ORM middleware repository that implements ICommonRepository.ExecuteStoredSelect(..) or (directly) IDbConnection.AggSelect(..) or IDbConnection.AggCompute(..) to select data from stored procedures...
Return Type
string
Parameters
# | Name | Type | Description | Default Value |
---|---|---|---|---|
1. | that | [ISpecification](./Common-Abstract-Library%20ISpecification.md) | specification invoker | |
2. | useSkipAndTakeFormat | bool | If true skip and take is included. It must be used with a combination of the extension IDbConnection.AggSelect(..) or IDbConnection.AggCompute(..) using skip and take instantiated. | |
3. | debugMode | bool | If true, non-minimized query is generated for a debug purpose. If false, minimized query (with better performance) is generated for production purpose. | |
4. | parameters | IDictionary<int, object?> | filter parameters; key := placeholder index; value := value |
Create<TEntity>(..) 1/3
public static ISpecification<TEntity> Create<TEntity>(ID3Context d3Context, bool forceInnerJoin = false, bool forceLeftJoin = false) where TEntity : class
Description
Creates a new instance of ISpecification<TEntity>.
Return Type
ISpecification<TEntity>
Type Parameters
TEntity : class
Parameters
# | Name | Type | Description | Default Value |
---|---|---|---|---|
1. | d3Context | [ID3Context](./Common-Library%20ID3Context.md) | D3Context | |
2. | forceInnerJoin | bool | Specifies if this specification should be joined by INNER JOIN even if joined by nullable (optional) "many to one" relation, where LEFT JOIN is used obviously, or joined by "one to many" relation, where LEFT JOIN is also used. | false |
3. | forceLeftJoin | bool | Specifies if this specification should be joined by LEFT JOIN even if joined by non-nullable (required) "many to one" relation. | false |
Create<TEntity, TParent>(..) 2/3
public static ISpecification<TEntity> Create<TEntity, TParent>(ID3Context d3Context, Expression<Func<TParent, TEntity?>> propToIncludeOnly, bool forceInnerJoin = false, bool forceLeftJoin = false) where TEntity : class where TParent : class
Description
Creates a new instance of ISpecification<TEntity> which is prepared to be appended to a parent specification only through the propToIncludeOnly (in case of more references from a single table).
Return Type
ISpecification<TEntity>
Type Parameters
- TEntity : class
- TParent : class
Parameters
# | Name | Type | Description | Default Value |
---|---|---|---|---|
1. | d3Context | [ID3Context](./Common-Library%20ID3Context.md) | D3Context | |
2. | propToIncludeOnly | Expression<Func<TParent, TEntity?>> | Sets D3BaseSpecification.ParentPropOnlyToInclude and the only reference that is related to the property is included. | |
3. | forceInnerJoin | bool | Specifies if this specification should be joined by INNER JOIN even if joined by nullable (optional) "many to one" relation, where LEFT JOIN is used obviously, or joined by "one to many" relation, where LEFT JOIN is also used. | false |
4. | forceLeftJoin | bool | Specifies if this specification should be joined by LEFT JOIN even if joined by non-nullable (required) "many to one" relation. | false |
Create<TInverseRoot, TResult>(..) 3/3
public static ISpecification<TResult> Create<TInverseRoot, TResult>(ID3Context d3Context, Expression<Func<TResult, IEnumerable<TInverseRoot>>> inverseRootCollection, Expression<Func<TInverseRoot, IComparable>> inverseRootForeignKey, bool forceInnerJoin = false, bool forceLeftJoin = false) where TInverseRoot : class where TResult : class
Description
Creates a new instance of ISpecification<TResult> which must be on the very left side of future joining (this specification cannot be appended to some parent one). The query result should be selected as List<TResult>. The top query context is of type TInverseRoot.
Return Type
ISpecification<TResult>
Type Parameters
- TInverseRoot : class
- TResult : class
Parameters
# | Name | Type | Description | Default Value |
---|---|---|---|---|
1. | d3Context | [ID3Context](./Common-Library%20ID3Context.md) | D3Context | |
2. | inverseRootCollection | Expression<Func<TResult, IEnumerable<TInverseRoot>>> | "one to many" aggregation of the query root into the query result type | |
3. | inverseRootForeignKey | Expression<Func<TInverseRoot, TResult>>? | "many to one" aggregation foreign key of the query root referencing the query result type | |
4. | forceInnerJoin | bool | Specifies if this specification should be joined by INNER JOIN even if joined by nullable (optional) "many to one" relation, where LEFT JOIN is used obviously, or joined by "one to many" relation, where LEFT JOIN is also used. | false |
5. | forceLeftJoin | bool | Specifies if this specification should be joined by LEFT JOIN even if joined by non-nullable (required) "many to one" relation. | false |
PreBuild<TEntity>(..)
public static void PreBuild<TEntity>(ISpecification<TEntity> that) where TEntity : class
Description
Prebuilds the specification in order to cache SQL part strings for building a final query.
Return Type
ISpecification<TEntity>
Type Parameters
TEntity : class
Parameters
# | Name | Type | Description | Default Value |
---|---|---|---|---|
1. | that | [ISpecification<TEntity>](./Common-Abstract-Library%20ISpecification-TEntity.md) | specification invoker |
RemoveFilterItems<TEntity, THolder>(..)
public static ISpecification<TEntity> RemoveFilterItems<TEntity, THolder>(ISpecification<TEntity> that, Expression<Func<THolder, IComparable?>> filterProp) where TEntity : class where THolder : class
Description
Returns a new specification with cloned filter created from that specification and removes all the filter items containing the specified filterProp.
Return Type
ISpecification<TEntity>
Type Parameters
- TEntity : class
- THolder : class
- TProp : IComparable
Parameters
# | Name | Type | Description | Default Value |
---|---|---|---|---|
1. | that | [[ISpecification<TEntity>](./Common-Abstract-Library%20ISpecification-TEntity.md) | specification invoker | |
2. | filterProp | Expression<Func<THolder, TProp>> | The property of any context to exclude from the filter context. If more than 1 references leading to this property, the filter clearing will be applied for all references. |
RemoveSortItem<TEntity, THolder>(..)
public static ISpecification<TEntity> RemoveSortItem<TEntity, THolder>(ISpecification<TEntity> that, Expression<Func<THolder, IComparable?>> sortProp) where TEntity : class where THolder : class
Description
Returns a new specification with cloned sort context created from that specification and removes all the sort items containing the specified sortProp.
Return Type
ISpecification<TEntity>
Type Parameters
- TEntity : class
- THolder : class
- TProp : IComparable
Parameters
# | Name | Type | Description | Default Value |
---|---|---|---|---|
1. | that | [[ISpecification<TEntity>](./Common-Abstract-Library%20ISpecification-TEntity.md) | specification invoker | |
2. | sortProp | Expression<Func<THolder, TProp>> | The property of any context to exclude from the sort context. |