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

Question: How to return Composite Primary Key in InsertAsync? #942

Open
biapar opened this issue Sep 28, 2021 · 7 comments
Open

Question: How to return Composite Primary Key in InsertAsync? #942

biapar opened this issue Sep 28, 2021 · 7 comments
Labels
question Further information is requested

Comments

@biapar
Copy link

biapar commented Sep 28, 2021

I've a generic SaveAsync

public virtual async Task<TReturn> SaveAsync<TReturn>(TEntity entity)
        {
            using ( var connection = GetConnection() )
            {
                return await connection.InsertAsync<TEntity, TReturn>(entity);
            }
        }

Called :

await MatrixAddonManager.SaveAsync<int>(MatrixAddon)

How to return a primary field that correspond to a composite primary key?

Thanks

@biapar biapar added the question Further information is requested label Sep 28, 2021
@mikependon
Copy link
Owner

@biapar - it is unfortunate, the composite keys are not supported with RepoDB. It is also a part of our limitation page.

image

@biapar
Copy link
Author

biapar commented Sep 29, 2021

I by passed using this code

SaveAsync<object>

@mikependon
Copy link
Owner

Does it work? Pretty sure RepoDB could not handle the generated ID of composite keys. 😄

@biapar
Copy link
Author

biapar commented Sep 29, 2021

Works. It give me only the first field of the key. I'll tried again.

@biapar
Copy link
Author

biapar commented Sep 29, 2021

I've the composite key

         modelBuilder.Entity<Sample>()
                .HasKey(c => new { c.Data, c.Lotto, c.Barcode });

and the insert return me the first field of the table because I tried also with other table with other composite field and give me the first field of the table.

@mikependon
Copy link
Owner

Was not it a problem in your case? It should somehow return you the values of the composite fields (more than 1 field).
RepoDB is not handling multiple composite values (from composite keys) - IMO

@biapar
Copy link
Author

biapar commented Sep 30, 2021

Not in my case for this tables, for others yes, but it's important that the row will be saved. For me is not important to get the key of the insert because I know it and the 90% of time I try to not use the identity key.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants