Вход на сайт
Подскажите по чату ГПТ
1942 просмотров
Перейти к просмотру всей ветки
в ответ Срыв покровов 03.03.23 22:25
продолжение
I need one more generic function to update property of entities.
It should get a type, a condition and an a action with setter. Can you make it?
Ответ
public static void UpdateEntities<T>(Func<T, bool> condition, Action<T> setter) where T : class
{
using (var context = new YourDbContext())
{
var entitiesToUpdate = context.Set<T>().Where(condition).ToList();
entitiesToUpdate.ForEach(setter);
context.SaveChanges();
}
}