-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathProgram.cs
53 lines (40 loc) · 1.4 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
53
DeltaExtensions.UseResponseDiagnostics = true;
var sqlInstance = new SqlInstance<SampleDbContext>(constructInstance: builder => new(builder.Options));
await using var database = await sqlInstance.Build("WebAppEF");
var connectionString = database.ConnectionString;
#region UseDeltaSQLServerEF
var builder = WebApplication.CreateBuilder();
builder.Services.AddSqlServer<SampleDbContext>(connectionString);
var app = builder.Build();
app.UseDelta<SampleDbContext>();
#endregion
var context = database.Context;
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($"RowVersion: {company.RowVersion}");
result.AppendLine($"Content: {company.Content}");
}
await _.Response.WriteAsync(result.ToString());
});
#region UseDeltaMapGroupEF
app.MapGroup("/group")
.UseDelta<SampleDbContext>()
.MapGet("/", () => "Hello Group!");
#endregion
app.Run();