Код: Выделить всё
var updated = await db.PublicConfigurationRoletypeWaitingTime
.Where(x => x.TypeId.Contains((int)personRoleType))
.ExecuteUpdateAsync(x => x.SetProperty(y => y.Waitingtime, waitingTime.Value));
Я заметил, что мои тесты иногда не удались, поскольку было неправильное время.
, так что я добавлял утверждения после обновления базы:
var updated = await db.PublicConfigurationRoletypeWaitingTime
.Where(x => x.TypeId.Contains((int)personRoleType))
.ExecuteUpdateAsync(x => x.SetProperty(y => y.Waitingtime, waitingTime.Value));
// was it updated?
updated.Should().Be(1, $"Waiting time for {personRoleType} should be updated");
// yes one row was changed
// get the entry from the db - The same where clause then above
var test = await db.PublicConfigurationRoletypeWaitingTime
.Where(x => x.TypeId.Contains((int)personRoleType))
.ToListAsync();
// should be exactly one entry, not something like have multiple matching entries and returning a random one
test.Should().HaveCount(1);
// yes
// Ok maybe it has old values cached, so reload the entity
var entity = db.Entry(test.First());
await entity.ReloadAsync();
// Now it should have the correct value from the database
test.First().Waitingtime.Should().Be(waitingTime.Value);
// NOPE it failed
< /code>
Для контекста, то есть класс для таблицы: < /p>
Код: Выделить всё
[Table("configuration_roletype_waiting_time")]
public partial class PublicConfigurationRoletypeWaitingTime
{
[Key]
[Column("id")]
public global::System.Int32 Id { get; set; }
[Column("type_id")]
public global::System.Collections.Generic.List TypeId { get; set; } = null!;
[Column("waitingtime")]
public global::System.TimeSpan Waitingtime { get; set; }
[Column("notification_time")]
public global::System.TimeSpan NotificationTime { get; set; }
[Column("notification_text")]
public global::System.String NotificationText { get; set; } = null!;
[Column("safe_deletion_threshold")]
public global::System.Int32 SafeDeletionThreshold { get; set; }
[Column("import_deletion_threshhold")]
public global::System.TimeSpan? ImportDeletionThreshhold { get; set; }
[Column("import_deletion_faild_requests")]
public global::System.Int32? ImportDeletionFaildRequests { get; set; }
[Column("import_deletion_faild_requests_threshhold")]
public global::System.Int32? ImportDeletionFaildRequestsThreshhold { get; set; }
[Column("import_threshhold_check")]
public global::System.TimeSpan? ImportThreshholdCheck { get; set; }
}
< /code>
И вот таблица: < /p>
CREATE TABLE public.configuration_roletype_waiting_time
(
id integer NOT NULL,
type_id integer[] NOT NULL,
waitingtime interval NOT NULL,
notification_time interval NOT NULL,
notification_text text NOT NULL,
safe_deletion_threshold integer NOT NULL,
import_deletion_threshhold interval,
import_deletion_faild_requests integer,
import_deletion_faild_requests_threshhold integer,
import_threshhold_check interval
);
< /code>
Что мне не хватает? Я в растерянности. Я мог бы загрузить сущность, изменить его, а затем выполнить db.savechanges () чрезвычайно вырезанная из обновленной переменной во втором блоке кода…
Подробнее здесь: https://stackoverflow.com/questions/797 ... o-database
Мобильная версия