2

Using dapper.contrib, I keep getting the error: '42P01: relation "tblproduct" does not exist'.

I believe this to be because postgresql is case sensitive. The entity itself has the schema annotation of '[Table("tblProduct")]'.

I can't find why the generated sql will use a lowercase tablename? I'm using the 'SqlMapperExtensions.TableNameMapper' to force the case but this doesn't work either. Am I missing something? Thanks

    public ICollection<Product> GetAll(int count)
    {
        if (SqlMapperExtensions.TableNameMapper != null)
            return null;

        SqlMapperExtensions.TableNameMapper = (type) =>
        {
            return "tblProduct";
        };

        using (var connection = new NpgsqlConnection(connectionString))
        {
            connection.Open();
            return connection.GetAll<Product>().Take(count).ToList();
        }
    }
Tikeb
  • 978
  • 3
  • 9
  • 25
  • For anyone coming across this: I believe dapper.contrib sets all table/column names to lowercase. I've not found a way to force it to use any other case. Will try dapper extensions instead – Tikeb Oct 26 '18 at 08:22

1 Answers1

1

You can see what Dapper is generating with :

NpgsqlLogManager.Provider = new ConsoleLoggingProvider(NpgsqlLogLevel.Trace, true, true);

I fixed my problem on PostgresSQL with qutoes :

SqlMapperExtensions.TableNameMapper = (type) => $"\"{type.Name}s\"";
Adam Paquette
  • 1,243
  • 1
  • 14
  • 28