Dapper.Contrib icon indicating copy to clipboard operation
Dapper.Contrib copied to clipboard

Remove "RETURNING *" or "RETURNING Id" in Dapper.Contrib

Open dogac00 opened this issue 4 years ago • 1 comments

Currently, it seems to me that Dapper.Contrib's InsertAsync generates SQL with RETURNING, is there any way we can remove this with configuration? If not, supporting it would be great.

My problem is InsertAsync adds RETURNING Id at the end of my query. But my column name is "Id" with quotes. But when this query is sent to PostgreSQL, it gives this error: Column id does not exist. Removing the last returning clause will solve my problem because I'm not using any return value in my insert query.

Also, in PostgresAdapter, AddColumnName adds with quotes like this "Price", but adding returning clause adds without quotes like this: Id.

The code that causes "Column id does not exist" error:

[Table("\"Products\"")]
public class Product
{
    public long Id { get; set; }
    public string Name { get; set; }
}

public async Task<int> InsertAsync(IDbConnection connection, Product product)
{
    return await connection.InsertAsync(product);
}

My database schema:

Screen Shot 2020-09-22 at 13 14 38

dogac00 avatar Sep 18 '20 10:09 dogac00

@dogac00 , Postgres being a case sensitive database, Ideally I would either use Lowercase or Snake case for column names

maulik-modi avatar Jun 17 '21 03:06 maulik-modi