I have the following:
foreach (var objectiveDetail in add)
{
_uow.ObjectiveDetails.Add(objectiveDetail);
}
Is there a way I could do this in LINQ.
I have the following:
foreach (var objectiveDetail in add)
{
_uow.ObjectiveDetails.Add(objectiveDetail);
}
Is there a way I could do this in LINQ.
Or just:
_uow.ObjectiveDetails.AddRange(add);
add.Foreach(o => _uow.ObjectiveDetails.Add(o));
Try the above
Here is another answer/question ToList().ForEach in Linq
You mean something like this?
add.ForEach( (objectiveDetail) => _uow.ObjectiveDetails.Add(objectiveDetail));
By the way this is not LINQ.
This is just a method of generic List<T>
class.
You could do this in a foreach if add
is a List<T>
by calling the method ForEach(Action<T> action)
Such as.
add.ForEach(item => _uow.ObjectiveDetails.Add(item));