You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Configurations;
using DotNet.Testcontainers.Containers;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
var _dbContainer = new TestcontainersBuilder<PostgreSqlTestcontainer>()
.WithDatabase(new PostgreSqlTestcontainerConfiguration
{
Database = "db",
Username = "postgres",
Password = "postgres",
})
.WithImage("postgres:latest")
.WithPortBinding(80, true)
.WithCleanUp(true)
.Build();
await _dbContainer.StartAsync();
var dbContext = CreateContext();
dbContext.Database.EnsureCreated();
dbContext.StatusEntities.Add(new Status()
{
Id = 1,
LastChecked = DateTime.UtcNow - TimeSpan.FromDays(1),
Name = "blah"
});
await dbContext.SaveChangesAsync();
dbContext.StatusEntities.Upsert(new Status()
{
Id = 1,
Name = "mine"
}).Run();
Console.WriteLine(JsonConvert.SerializeObject(await dbContext.StatusEntities.ToListAsync()));
ApplicationContext CreateContext()
{
var connectionString = _dbContainer.ConnectionString;
return new ApplicationContext(
new DbContextOptionsBuilder<ApplicationContext>().UseNpgsql(connectionString).Options);
}
public class Status
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
public long Id { get; set; }
public string Name { get; set; }
public DateTime LastChecked { get; set; }
}
public class ApplicationContext : DbContext
{
public ApplicationContext(DbContextOptions<ApplicationContext> options)
: base(options)
{
}
public DbSet<Status> StatusEntities { get; set; }
}
I have a console app here that tries to update StatusEntity on the Id column, however the name field doesn't change. Any ideas as to what's happening here?
The text was updated successfully, but these errors were encountered:
I have a console app here that tries to update
StatusEntity
on the Id column, however the name field doesn't change. Any ideas as to what's happening here?The text was updated successfully, but these errors were encountered: