When I want to insert an object into my database, I receive an error:
object reference not set to an instance of an object
when the primary key field for the object is null
. When I set some value to the field, it works fine.
My table creation :
create table Appointment
(
AppointmentUUID uuid DEFAULT uuid_generate_v4 () primary key,
};
My class :
public class Appointment
{
public Guid? AppointmentUUID { get; set; }
public void Insert(NpgsqlConnection conn)
{
var i = conn.Insert(this);
}
}
My calling code :
var lConnection = new NpgsqlConnection(connstring);
lConnection.Open();
var a = Appointment.Get2(allAppoints.FirstOrDefault().AppointmentUUID.Value, lConnection);
var newApp = new Appointment();
newApp.Insert(lConnection);
Surely there must be a way I can insert an object and let the database create it's own Guid
. What am I missing?