Reputation: 1068
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();
}
}
Upvotes: 2
Views: 1848
Reputation: 8
If the table name in the database is the plural form of the class name, you can use this
SqlMapperExtensions.TableNameMapper = (type) => $"\"{Inflector.Inflector.Pluralize(type.Name)}\"";
Upvotes: 0
Reputation: 1393
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\"";
Upvotes: 1