You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LuEfDataAccess.cs 786B

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. using Luticate2.Utils.Dbo;
  3. using Microsoft.EntityFrameworkCore;
  4. namespace Luticate2.Utils.DataAccess
  5. {
  6. public abstract class LuEfDataAccess<TModel, TDbContext> : LuDataAccess
  7. where TModel : class
  8. where TDbContext : DbContext
  9. {
  10. protected readonly TDbContext Db;
  11. protected readonly DbSet<TModel> Table;
  12. protected LuEfDataAccess(TDbContext db, DbSet<TModel> table)
  13. {
  14. Db = db;
  15. Table = table;
  16. }
  17. public LuResult<T> Execute<T>(Func<LuResult<T>> func)
  18. {
  19. try
  20. {
  21. return func();
  22. }
  23. catch (Exception e)
  24. {
  25. return LuResult<T>.Error(LuStatus.DbError, e);
  26. }
  27. }
  28. }
  29. }