Skip to content

Feature: Fluent API for Configuration and Entity Type Mappings #3

@rent-a-developer

Description

@rent-a-developer

Add Fluent API for Configuration and Entity Type Mappings

Summary

Implement a fluent API that enables configuring general settings (e.g., EnumSerializationMode) and defining entity type mappings in a flexible, code-first style.

Example

DbConnectionExtensions.Configure(config =>
    {
        config.EnumSerializationMode = EnumSerializationMode.Integers;
        config.InterceptDbCommand = (command, tempTables) =>
        {
            //... log command
        };

        // Table name mapping:
        config.Entity<Product>()
            .ToTable("Products");

        // Column name mapping:
        config.Entity<Product>()
            .Property(a => a.Name)
            .HasColumnName("ProductName");

        // Key column mapping:
        config.Entity<Product>()
            .Property(a => a.Id)
            .IsKey();

        // Database generated column mapping:
        config.Entity<Product>()
            .Property(a => a.DiscountedPrice)
            .IsDatabaseGenerated();

        // Ignored property mapping:
        config.Entity<Product>()
            .Property(a => a.IsOnSale)
            .Ignore();
    }
);

Requirements

  1. General Configuration Support:
    • Enable setting global options such as:
      • EnumSerializationMode
      • InterceptDbCommand delegate
  2. Entity Type Mapping Support:
    Allow configuring entity types and their properties with the following capabilities:
    • Specify the table name for an entity
    • Specify column names for properties
    • Mark one or more properties as primary keys
    • Mark properties as database-generated (computed or identity)
    • Exclude properties from mapping (ignore them)

Expected behavior

  • Fluent API configurations take precedence over any data annotation attributes applied to the entity classes or their properties.
  • When a fluent mapping exist for an entity type, the data annotations on this entity type are ignored.
  • When a fluent mapping exists for an entity property, the data annotations on this property are ignored.
  • If no fluent configuration is provided for an entity type or an entity property, the system falls back to existing behavior using data annotation attributes.
  • After DbConnectionExtensions.Configure has been called, the configuration of DbConnectionPlus must be frozen. Any further attempt to modify the configuration should throw an InvalidOperationException.

Testing

Provide comprehensive unit and integration tests across all supported database systems to verify:

  • General configuration options are applied correctly.
  • CRUD operations respect fluent API mappings and function as expected.
  • Query translations correctly honor fluent API mappings.
  • Temporary table creation and usage behave correctly when configured via fluent API.

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions