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();
}
}
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\"";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.