Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EnumToString not working in BatchUpdateAsync #397

Closed
IeuanWalker opened this issue Sep 28, 2020 · 5 comments
Closed

EnumToString not working in BatchUpdateAsync #397

IeuanWalker opened this issue Sep 28, 2020 · 5 comments

Comments

@IeuanWalker
Copy link

Hi,

I have this table -

[Table("Settings")]
public class SettingsTbl
{
    [Key]
    public SettingsEnum Setting { get; set; }
    [Required]
    [MaxLength(20)]
    public string Value { get; set; }
}

and this in the database context -

modelBuilder
    .Entity<SettingsTbl>()
    .Property(e => e.Setting)
    .HasConversion<string>();

Calling this method -

public async Task UpdateSetting(SettingsEnum setting, object value)
{
    await dbSet
        .Where(x => x.Setting == setting)
        .BatchUpdateAsync(x => new SettingsTbl
        {
            Value = value.ToString()
        })
        .ConfigureAwait(false);
}

Throws the following error -
image

Using NuGet version - 3.2.3

@borisdj
Copy link
Owner

borisdj commented Sep 30, 2020

Conversion is not currently supported for Batch.

@IeuanWalker
Copy link
Author

@borisdj thanks, is this being planned?

Not too familiar how this package works, but if I figure out how to add this feature ill create a PR for it.

@borisdj
Copy link
Owner

borisdj commented Oct 6, 2020

If you manage to do it, you can send PR.

@borisdj
Copy link
Owner

borisdj commented Mar 13, 2021

Solved with latest version.

When doing Batch with named parameter on table that has enum Conversion (Int to String) the name of parameter has to be same as Property name (Case-insensitive), example:
context.Settings.Where(x => x.Settings == settings).BatchUpdate(x => new Setting { Value = value.ToString() });

Explicit enum values will also work:
...Where(x => x.Settings == SettingsEnum.Sett1)...

@borisdj
Copy link
Owner

borisdj commented Mar 22, 2021

As of Now it works even with different named params.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants