Skip to content

Add IDictionary support to Update data expressions#2163

Merged
jzabroski merged 2 commits into
mainfrom
copilot/fix-981
Nov 11, 2025
Merged

Add IDictionary support to Update data expressions#2163
jzabroski merged 2 commits into
mainfrom
copilot/fix-981

Conversation

Copilot AI commented Sep 8, 2025

Copy link
Copy Markdown
Contributor

This PR adds support for IDictionary<string, object> parameters to Update data expressions, bringing them in line with the existing Insert data expression functionality.

Problem

Previously, Update expressions only accepted anonymous objects for Set and Where operations:

// This worked, but required compile-time knowledge of column names
Update.Table("Users")
    .Set(new { Name = "Updated Name", Status = "Active" })
    .Where(new { Id = 123 });

However, Insert expressions already supported both anonymous objects and IDictionary:

// Insert supported both approaches
Insert.IntoTable("Users").Row(new { Name = "Test" });  // Anonymous object
Insert.IntoTable("Users").Row(new Dictionary<string, object> { ["Name"] = "Test" });  // IDictionary

This inconsistency made it impossible to build dynamic Update statements where column names and values are determined at runtime.

Solution

This PR adds IDictionary overloads to the Update expression interfaces and implementation:

// NEW: Now both approaches work for Update too
Update.Table("Users")
    .Set(new Dictionary<string, object> 
    {
        ["Name"] = "Updated Name",
        ["Status"] = "Active",
        ["LastModified"] = DateTime.Now
    })
    .Where(new Dictionary<string, object>
    {
        ["Id"] = 123,
        ["TenantId"] = "tenant-456"
    });

Changes Made

  1. Enhanced ExpressionBuilderBase.GetData - Added support for IDictionary<string, object> input directly
  2. Extended interfaces - Added IDictionary overloads to IUpdateSetSyntax and IUpdateWhereSyntax
  3. Updated implementation - Added corresponding methods to UpdateDataExpressionBuilder
  4. Comprehensive tests - Added full test coverage for new functionality and backward compatibility

Benefits

  • Dynamic Updates: Enables building Update statements where column names/values are determined at runtime
  • Generic Migrations: Allows creating reusable migration classes that work with any table/columns
  • API Consistency: Update now works the same way as Insert regarding parameter types
  • Backward Compatible: All existing code using anonymous objects continues to work unchanged
  • Bonus: Delete and other data expressions automatically gained IDictionary support through the shared GetData method

Testing

All changes are thoroughly tested with both new IDictionary functionality and existing anonymous object usage to ensure no regressions.

Fixes #981.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Make all data expressions IDictionary aware (like Row) Add IDictionary support to Update data expressions Sep 8, 2025
Copilot AI requested a review from jzabroski September 8, 2025 12:33
@PhenX

PhenX commented Sep 11, 2025

Copy link
Copy Markdown
Collaborator
  • I'm not sure why it removed the header comments
  • It should add integration tests (or complete existing ones) with new cases with IDictonary

@jzabroski
jzabroski marked this pull request as ready for review November 11, 2025 15:32
@jzabroski
jzabroski merged commit 620b8b0 into main Nov 11, 2025
1 check passed
@jzabroski jzabroski modified the milestones: 7.3.0, 7.2.0 Nov 11, 2025
@jzabroski
jzabroski deleted the copilot/fix-981 branch November 11, 2025 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make all data expressions IDictionary aware (like Row)

3 participants