DapperLib / DapperLib/Dapper.Contrib
InsertAsync returning 0 as Id on a class that has ExplicitKey attribute on Id
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 293
- Forks
- 109
- PR merge metrics
- No merged PRs in 30d
Description
` public class Customer
{
[ExplicitKey]
public int Id { get; set; }
[Write(false)]
public string FullName { get; set; }
public string Username { get; set; }
public string Email { get; set; }
public string EmailToRevalidate { get; set; }
public string SystemName { get; set; }
public int BillingAddress_Id { get; set; }
public int Add(Customer customer)
{
using (IDbConnection conn = Connection)
{
var result = conn.InsertAsync(customer).Result; // need to fix this it is return 0 because of the explicitkey attribue on ID.
return result;
}
}
`
I need this function to return the "manually" inserted Id / Object back. Or somehow check if the insert was successful.
I believe this is somewhat buggy if it just return 0 and does not acknowledge the fact that I am using ExplicitKey attribute on Id property. Like this how am I supposed to tell if it was successful or not ?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the Customer class and conn.InsertAsync(customer).Result, then trace the InsertAsync implementation and its ExplicitKey handling. Check related tests for insert return values; done means a manually supplied Id is acknowledged or a clear success result is provided, with regression coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100