RepoDB: Bug: Typed "UpdateAsync" fails for composite key table

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: https://github.com/mikependon/RepoDb/issues/485

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (9 by maintainers)

Commits related to this issue

Most upvoted comments

It works now. Thanks a ton!

Great library by the way. Composite keys work fine when using where-objects and expressions. I haven’t found other (small) libs that support it so easily