Вход на сайт
Подскажите по чату ГПТ
1942 просмотров
Перейти к просмотру всей ветки
в ответ alex445 04.03.23 00:19, Последний раз изменено 04.03.23 08:27 (Срыв покровов)
По-моему просто охуенно
Here's an example function that meets your requirements using C# 10:
public static class EntityUpdater
{
public static (string Name, TimeSpan ElapsedTime) UpdateEntity(Func condition, Action setter) where T : class
{
using var context = new MyDbContext(); // replace with your own DbContext class
var stopwatch = new Stopwatch();
stopwatch.Start();
var entity = context.Set().FirstOrDefault(condition);
if (entity == null)
{
throw new InvalidOperationException("Entity not found");
}
setter(entity);
context.SaveChanges();
stopwatch.Stop();
return (typeof(T).Name, stopwatch.Elapsed);
}
}