Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var connection = "host=localhost;database=message_db;password=postgres;username=postgres";
- var message = new Message
- {
- Subject = "subject",
- BodyHtml = "Html",
- BodyText = "Text"
- };
- var recipients = new List<Recipient>
- {
- new Recipient {Address = "jake@bob.com", Name = "Jake Scott", RecipientTypeId = 1},
- new Recipient {Address = "ben@example.com", Name = "Ben Scott", RecipientTypeId = 2},
- new Recipient {Address = "suki@example.com", Name = "Ben Scott", RecipientTypeId = 3},
- };
- NpgsqlConnection.MapCompositeGlobally<Message>("message_dto");
- NpgsqlConnection.MapCompositeGlobally<Recipient>("recipient_dto");
- using (var connection = new NpgsqlConnection(connectionString))
- {
- connection.Open();
- connection.Execute("delete from recipient;");
- connection.Execute("delete from address;");
- connection.Execute("delete from message;");
- NpgsqlCommand command = connection.CreateCommand();
- command.CommandType = CommandType.StoredProcedure;
- command.CommandText = "create_message";
- command.Parameters.AddWithValue("message", message);
- command.Parameters.AddWithValue("recipients", recipients);
- using (NpgsqlDataReader reader = command.ExecuteReader())
- {
- reader.Read();
- var messageId = reader.GetInt64(0);
- Log.Information("MessageId: {messageId}", messageId);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement