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

DatabaseGenerated doesnt work with BulkSaveChangesAsync #1649

Open
WilliamScolago opened this issue Jan 7, 2025 · 0 comments
Open

DatabaseGenerated doesnt work with BulkSaveChangesAsync #1649

WilliamScolago opened this issue Jan 7, 2025 · 0 comments

Comments

@WilliamScolago
Copy link

WilliamScolago commented Jan 7, 2025

I have a model that basically look like this

public class Profile : BaseEntity, IComparable<Profile>
{
    [Display(Name = nameof(Resources.Models.Profile.LastName),
        ResourceType = typeof(Resources.Models.Profile))]
    [MaxLength(128)]
    public string? LastName { get; set; }

    [Display(Name = nameof(Resources.Models.Profile.FirstName),
        ResourceType = typeof(Resources.Models.Profile))]
    [MaxLength(128)]
    public string? FirstName { get; set; }

    [DatabaseGenerated(DatabaseGeneratedOption.Computed)]
    public string FullName
    {
        // Code-First do not change!
        get => $"{LastName} {FirstName}";
        // ReSharper disable once UnusedMember.Local
        // ReSharper disable once ValueParameterNotUsed
        private set { }
    }
    
    [MaxLength(128)]
    public string? PhoneNumber { get; set; }
}

If I update Profile (any properties, even PhoneNumber) and I use BulkSaveChangesAsync(), it throws this error :

{"The column \"FullName\" cannot be modified because it is either a computed column or is the result of a UNION operator."}

The only solution I found was to use the basic SaveChangesAsync(). Using [NotMapped] attribute isnt a solution since I'm using FullName in queries.

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

No branches or pull requests

1 participant