I needed to wrap some Linq queries with some Retry Policy logic.
Is it safe to pass this:
return WithRetry<User>(() =>
dataContext.Users.Where(u => u.UserID == userID).SingleOrDefault());
to this:
public TResult WithRetry<TResult>(Func<TResult> methodCall)
{
// My Try/Catch Retry Code
}
Or should the first line be constructed like this instead:
return WithRetry<User>(() =>
{
return dataContext.Users
.Where(u => u.UserID == userID)
.SingleOrDefault();
});
AFAIK, if the argument type of a method is
Func, calling it will automatically pass as a function without executing it. You don’t need to further wrap it in an anonymous function wrapper.