コード例 #1
0
        public static async Task Do <T>(this ITestTaskDbContext context, Func <DbSet <T>, Task> act, Boolean shouldSave = false)
            where T : class
        {
            await act(context.Set <T>());

            if (!shouldSave)
            {
                return;
            }

            await context.SaveChangesAsync();

            return;
        }
コード例 #2
0
        public static async Task <R> DoWithResult <T, R>(this ITestTaskDbContext context, Func <DbSet <T>, Task <R> > act, Boolean shouldSave = false)
            where T : class
        {
            var res = await act(context.Set <T>());

            if (!shouldSave)
            {
                return(res);
            }

            await context.SaveChangesAsync();

            return(res);
        }