DapperLib / Dapper.Contrib

Dapper community contributions - additional extensions for Dapper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

InsertAsync returning 0 as Id on a class that has ExplicitKey attribute on Id

kevinborg opened this issue · comments

`    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 ?

This unexpected behavior just cost me a day and a half! Needs to be better documented or altered to reflect the functionality of regular keys