| 1234567891011121314151617181920212223242526272829303132333435 |
- using System;
- using Luticate2.Utils.Dbo;
- using Microsoft.EntityFrameworkCore;
- using Microsoft.Extensions.Logging;
-
- namespace Luticate2.Utils.DataAccess
- {
- public class LuEfDataAccess<TModel, TDbo, TDbContext> : LuDataAccess
- where TModel : class
- where TDbo : class
- where TDbContext : DbContext, new()
- {
- protected readonly TDbContext Db;
-
- protected readonly DbSet<TModel> Table;
-
- protected LuEfDataAccess(TDbContext db, DbSet<TModel> table)
- {
- Db = db;
- Table = table;
- }
-
- public LuResult<T> Execute<T>(Func<TDbContext, DbSet<TModel>, LuResult<T>> func)
- {
- try
- {
- return func(Db, Table);
- }
- catch (Exception e)
- {
- return LuResult<T>.Error(LuStatus.DbError, e);
- }
- }
- }
- }
|