-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathProgram.cs
52 lines (42 loc) · 1.38 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var connectionString = PostgresConnection.ConnectionString;
#region UseDeltaPostgresEF
var builder = WebApplication.CreateBuilder();
builder.Services.AddDbContext<SampleDbContext>(
_ => _.UseNpgsql(connectionString));
var app = builder.Build();
app.UseDelta<SampleDbContext>();
#endregion
using (var scope = app.Services.CreateScope())
{
await using var context = scope.ServiceProvider.GetRequiredService<SampleDbContext>();
await context.Database.EnsureDeletedAsync();
await context.Database.EnsureCreatedAsync();
context.Add(
new Company
{
Content = "The company"
});
await context.SaveChangesAsync();
}
app.MapGet(
"/",
async _ =>
{
var result = new StringBuilder("Results: ");
result.AppendLine();
var dbContext = _.RequestServices.GetRequiredService<SampleDbContext>();
result.AppendLine($"LastTimeStamp: {await dbContext.GetLastTimeStamp()}");
result.AppendLine();
foreach (var company in await dbContext.Companies.ToListAsync())
{
result.AppendLine($"Id: {company.Id}");
result.AppendLine($"Content: {company.Content}");
}
await _.Response.WriteAsync(result.ToString());
});
#region UseDeltaMapGroupEF
app.MapGroup("/group")
.UseDelta<SampleDbContext>()
.MapGet("/", () => "Hello Group!");
#endregion
app.Run();