Class DbCommandSourceGenSettings
Namespace: Momentum.Extensions.SourceGenerators.DbCommand
Assembly: Momentum.Extensions.SourceGenerators.dll
Contains global configuration settings for the DbCommand source generator, extracted from MSBuild properties.
public record DbCommandSourceGenSettings : IEquatable<DbCommandSourceGenSettings>
Inheritance
object ← DbCommandSourceGenSettings
Implements
IEquatable<DbCommandSourceGenSettings>
Inherited Members
object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Examples
Example Configuration Effects:
// MSBuild configuration:
// <DbCommandDefaultParamCase>SnakeCase</DbCommandDefaultParamCase>
// <DbCommandParamPrefix>sp_</DbCommandParamPrefix>
[DbCommand(sp: "create_user")]
public record CreateUserCommand(
string FirstName, // → @sp_first_name
string LastName, // → @sp_last_name
[Column("email_addr")] string Email // → @email_addr (Column overrides prefix)
) : ICommand<int>;
// Generated ToDbParams():
public object ToDbParams()
{
var p = new
{
sp_first_name = this.FirstName,
sp_last_name = this.LastName,
email_addr = this.Email
};
return p;
}
Environment-Specific Configuration:
<!-- Development environment -->
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<DbCommandDefaultParamCase>None</DbCommandDefaultParamCase>
<DbCommandParamPrefix></DbCommandParamPrefix>
</PropertyGroup>
<!-- Production environment -->
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<DbCommandDefaultParamCase>SnakeCase</DbCommandDefaultParamCase>
<DbCommandParamPrefix>prod_</DbCommandParamPrefix>
</PropertyGroup>
Remarks
DbCommand Source Generator Settings Detailed Guide
MSBuild Integration
These settings are configured through MSBuild properties in the project file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<DbCommandDefaultParamCase>SnakeCase</DbCommandDefaultParamCase>
<DbCommandParamPrefix>p_</DbCommandParamPrefix>
</PropertyGroup>
</Project>
Parameter Name Generation Order
- Base Name: Start with C# property name (e.g., "FirstName")
- Column Override: Apply [Column("custom")] if present → "custom"
- Case Conversion: Apply DbCommandDefaultParamCase if no Column attribute → "first_name"
- Global Prefix: Apply DbCommandParamPrefix → "p_first_name"
Configuration Precedence
- Highest: [Column("name")] attribute on individual properties
- Medium: DbCommandAttribute.ParamsCase on individual commands
- Lowest: Global MSBuild settings (DbCommandDefaultParamCase, DbCommandParamPrefix)
Parameter Case Options
- None: Use property names as-is (e.g., "FirstName" → "@FirstName")
- SnakeCase: Convert to snake_case (e.g., "FirstName" → "@first_name")
Global Prefix Usage
The DbCommandParamPrefix is useful for:
- Stored Procedure Conventions: Some teams prefix all SP parameters (e.g., "p_user_id")
- Avoiding Keywords: Prefix to avoid SQL reserved words (e.g., "p_order" instead of "order")
- Multi-Tenant Systems: Different prefixes for different tenant databases
- Legacy System Integration: Match existing database parameter naming conventions
Build-Time Resolution
These settings are resolved during compilation from the MSBuild context, allowing different configurations for different build environments (Development, Staging, Production).
Constructors
DbCommandSourceGenSettings(DbParamsCase, string)
Contains global configuration settings for the DbCommand source generator, extracted from MSBuild properties.
public DbCommandSourceGenSettings(DbParamsCase DbCommandDefaultParamCase, string DbCommandParamPrefix)
Parameters
DbCommandDefaultParamCase
DbParamsCase
The default parameter case conversion to apply when DbCommandAttribute.ParamsCase is set to Unset. This provides a project-wide default for how property names are converted to database parameter names.
DbCommandParamPrefix
string
A global prefix to add to all generated parameter names. This is applied after case conversion and Column attribute overrides. Useful for database systems that require parameter prefixes.
Examples
Example Configuration Effects:
// MSBuild configuration:
// <DbCommandDefaultParamCase>SnakeCase</DbCommandDefaultParamCase>
// <DbCommandParamPrefix>sp_</DbCommandParamPrefix>
[DbCommand(sp: "create_user")]
public record CreateUserCommand(
string FirstName, // → @sp_first_name
string LastName, // → @sp_last_name
[Column("email_addr")] string Email // → @email_addr (Column overrides prefix)
) : ICommand<int>;
// Generated ToDbParams():
public object ToDbParams()
{
var p = new
{
sp_first_name = this.FirstName,
sp_last_name = this.LastName,
email_addr = this.Email
};
return p;
}
Environment-Specific Configuration:
<!-- Development environment -->
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<DbCommandDefaultParamCase>None</DbCommandDefaultParamCase>
<DbCommandParamPrefix></DbCommandParamPrefix>
</PropertyGroup>
<!-- Production environment -->
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<DbCommandDefaultParamCase>SnakeCase</DbCommandDefaultParamCase>
<DbCommandParamPrefix>prod_</DbCommandParamPrefix>
</PropertyGroup>
Remarks
DbCommand Source Generator Settings Detailed Guide
MSBuild Integration
These settings are configured through MSBuild properties in the project file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<DbCommandDefaultParamCase>SnakeCase</DbCommandDefaultParamCase>
<DbCommandParamPrefix>p_</DbCommandParamPrefix>
</PropertyGroup>
</Project>
Parameter Name Generation Order
- Base Name: Start with C# property name (e.g., "FirstName")
- Column Override: Apply [Column("custom")] if present → "custom"
- Case Conversion: Apply DbCommandDefaultParamCase if no Column attribute → "first_name"
- Global Prefix: Apply DbCommandParamPrefix → "p_first_name"
Configuration Precedence
- Highest: [Column("name")] attribute on individual properties
- Medium: DbCommandAttribute.ParamsCase on individual commands
- Lowest: Global MSBuild settings (DbCommandDefaultParamCase, DbCommandParamPrefix)
Parameter Case Options
- None: Use property names as-is (e.g., "FirstName" → "@FirstName")
- SnakeCase: Convert to snake_case (e.g., "FirstName" → "@first_name")
Global Prefix Usage
The DbCommandParamPrefix is useful for:
- Stored Procedure Conventions: Some teams prefix all SP parameters (e.g., "p_user_id")
- Avoiding Keywords: Prefix to avoid SQL reserved words (e.g., "p_order" instead of "order")
- Multi-Tenant Systems: Different prefixes for different tenant databases
- Legacy System Integration: Match existing database parameter naming conventions
Build-Time Resolution
These settings are resolved during compilation from the MSBuild context, allowing different configurations for different build environments (Development, Staging, Production).
DbCommandSourceGenSettings(DbCommandSourceGenSettings)
protected DbCommandSourceGenSettings(DbCommandSourceGenSettings original)
Parameters
original
DbCommandSourceGenSettings
Properties
DbCommandDefaultParamCase
The default parameter case conversion to apply when DbCommandAttribute.ParamsCase is set to Unset. This provides a project-wide default for how property names are converted to database parameter names.
public DbParamsCase DbCommandDefaultParamCase { get; init; }
Property Value
DbCommandParamPrefix
A global prefix to add to all generated parameter names. This is applied after case conversion and Column attribute overrides. Useful for database systems that require parameter prefixes.
public string DbCommandParamPrefix { get; init; }
Property Value
EqualityContract
protected virtual Type EqualityContract { get; }
Property Value
Methods
<Clone>$()
public virtual DbCommandSourceGenSettings <Clone>$()
Returns
Deconstruct(out DbParamsCase, out string)
public void Deconstruct(out DbParamsCase DbCommandDefaultParamCase, out string DbCommandParamPrefix)
Parameters
DbCommandDefaultParamCase
DbParamsCase
DbCommandParamPrefix
string
Equals(object?)
public override bool Equals(object? obj)
Parameters
obj
object?
Returns
Equals(DbCommandSourceGenSettings?)
public virtual bool Equals(DbCommandSourceGenSettings? other)
Parameters
other
DbCommandSourceGenSettings?
Returns
GetHashCode()
public override int GetHashCode()
Returns
PrintMembers(StringBuilder)
protected virtual bool PrintMembers(StringBuilder builder)
Parameters
builder
StringBuilder
Returns
ToString()
public override string ToString()
Returns
Operators
operator ==(DbCommandSourceGenSettings?, DbCommandSourceGenSettings?)
public static bool operator ==(DbCommandSourceGenSettings? left, DbCommandSourceGenSettings? right)
Parameters
left
DbCommandSourceGenSettings?
right
DbCommandSourceGenSettings?
Returns
operator !=(DbCommandSourceGenSettings?, DbCommandSourceGenSettings?)
public static bool operator !=(DbCommandSourceGenSettings? left, DbCommandSourceGenSettings? right)
Parameters
left
DbCommandSourceGenSettings?
right
DbCommandSourceGenSettings?