Currently I'm working on a little project with .NET Core and PostgreSQL. For my data acccess, I would like to use Dapper.Contrib
. Right now, I'm facing the following problem:
The following snippet shows the CREATE_DATABASE.sql
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE TABLE posts (
id UUID DEFAULT uuid_generate_v4 (),
created BIGINT,
value VARCHAR NOT NULL,
PRIMARY KEY (Id)
);
And the following is my model class in .NET Core
[Table("posts")]
public class Post
{
[Column("id")]
public Guid Id { get; set; }
[Column("created")]
public long Created { get; set; }
[Column("value")]
public string Value { get; set; }
}
The insert method looks like this (it is in the base class. In this case T is type of Post):
public void Insert(T entity)
{
_connection.Insert(entity);
}
When trying to insert an Post
object, I'm running into following error:
Ein Ausnahmefehler des Typs "Npgsql.PostgresException" ist in System.Private.CoreLib.dll aufgetreten.: '42703: column "Created" of relation "posts" does not exist
When set NpgsqlLogManager.Provider
to new ConsoleLoggingProvider(NpgsqlLogLevel.Trace, true, true);
there is the following INSERT
statement logged:
DEBUG [14313] Executing statement(s):
insert into posts ("Created", "Value") values ($1, $2) RETURNING Id
So, where is the problem here? I thought Dapper.Contrib
is doing fine with attributes, but obviously it isn't.
Does anybody know how to fix this issue, except of rename the model properties into lower case?
Thank you so far.