Deutsch
Germany.ruФорумы → Архив Досок→ Программирование

Подскажите по чату ГПТ

03.03.23 22:30
Re: Подскажите по чату ГПТ
 

продолжение

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();

}

}

 

Перейти на