Created
November 26, 2023 13:07
-
-
Save navferty/1cdc6e361c5b5565c6023d61b95a499e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.EntityFrameworkCore; | |
using Npgsql; | |
using Npgsql.NameTranslation; | |
var context = new Ctx(); | |
/* | |
CREATE TYPE enum_encounter_batch_item_status AS ENUM ('Invalid', 'Processed'); | |
create table "Items" | |
("Id" integer not null, | |
"Status" enum_encounter_batch_item_status not null); | |
*/ | |
var encounterBatchItems = new[] | |
{ | |
new EncounterBatchItem | |
{ | |
Id = 777, | |
Status = EncounterBatchItemStatus.Invalid, | |
}, | |
new EncounterBatchItem | |
{ | |
Id = 888, | |
Status = EncounterBatchItemStatus.Processed, | |
} | |
}; | |
context.Items.AddRange(encounterBatchItems); | |
await context.SaveChangesAsync(); | |
public enum EncounterBatchItemStatus | |
{ | |
Invalid, | |
Processed | |
} | |
public class EncounterBatchItem | |
{ | |
public long Id { get; set; } | |
public EncounterBatchItemStatus Status { get; set; } | |
} | |
class Ctx : DbContext | |
{ | |
public Ctx(DbContextOptions options) : base(options) | |
{ | |
} | |
public Ctx() | |
{ | |
} | |
public DbSet<EncounterBatchItem> Items { get; set; } | |
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) | |
{ | |
NpgsqlConnection.GlobalTypeMapper | |
.MapEnum<EncounterBatchItemStatus>("enum_encounter_batch_item_status", new NpgsqlNullNameTranslator()); | |
optionsBuilder.UseNpgsql("Server=127.0.0.1;Port=5432;Userid=postgres;Password=***;Database=postgres"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment