Skip to content

Bug: Typed "UpdateAsync" fails for composite key table #493

@asleire

Description

@asleire

I am using package FluentMigrator.Runner.SqlServer version 3.2.7

The following code:

IDbConnection db = ...;
                    
await db.UpdateAsync(
  dbo,
  d => d.SettingCollectionKey == collection.Key && d.Key == value.Key
);
`dbo` Model
    [Table("SettingCollectionValue")]
    internal class SettingCollectionValueDbo
    {
        public string? SettingCollectionKey { get; set; }

        public string? Key { get; set; }

        public string? Label { get; set; }

        public string? Value { get; set; }
    }

Fails with error Microsoft.Data.SqlClient.SqlException (0x80131904): The variable name '@SettingCollectionKey' has already been declared. Variable names must be unique within a query batch or stored procedure.

A workaround is using the non-typed UpdateAsync overload

Workaround
await db.UpdateAsync(
    "SettingCollectionValue",
    new
    {
        dbo.Label,
        dbo.Value,
    },
    new[]
    {
        new QueryField("SettingCollectionKey", dbo.SettingCollectionKey),
        new QueryField("Key", dbo.Key),
    }
);

Possibly related: #485

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingdeployedFeature or bug is deployed at the current releasefixedThe bug, issue, incident has been fixed.priorityTop priority feature or things to dotodoThings to be done in the future

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions