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

Upsert inserts empty values #146

Open
enriquinho-catalan opened this issue Mar 28, 2023 · 0 comments
Open

Upsert inserts empty values #146

enriquinho-catalan opened this issue Mar 28, 2023 · 0 comments

Comments

@enriquinho-catalan
Copy link

enriquinho-catalan commented Mar 28, 2023

With definition of

public enum MyEnum
{
    X = 0,
    Y = 1,
}

public class MyGroup
{

    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.None)]
    public long MyId;

    public MyEnum en;
}

MyGroup is marked as having an int conversion in model builder launch context:

            entity.Property(e => e.en)
                .HasColumnName("column_name")
                .HasConversion<int>();

The following upsert command yields the following SQL:
INSERT INTO "my_table" AS "T" () VALUES () ON CONFLICT ("my_id") DO UPDATE SET "en" = $1
Columns and values are left empty, which I believe is a bug.

    var myGroup = new MyGroup
        {
            MyId = 1,
            en = MyEnum.X,
        };
    
    _dbContext.MyGroups.Upsert(myGroup).WhenMatched(group =>
        new MyGroup
        {
            en = myGroup.en,
        }).Run();

If I try using the 2 parameter WhenMatched method, I get a different error:

    _dbContext.MyGroups.Upsert(myGroup).WhenMatched((dbGroup, insGroup) =>
        new MyGroup
        {
            en = insGroup.en,
        }).Run();

I get the error
This type of expression is not currently supported: insGroup. Simplify the expression, or try a different one .See https://go.flexlabs.org/upsert.expressions for more details

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