Code: Select all
DbSetCode: Select all
DbContextCode: Select all
public class MyEfRepository : IMyRepository
{
private readonly DbSet _myModels;
public MyEfRepository(MyDbContext ctx)
{
_myModels = ctx.MyModels;
}
public MyModel FindById(Guid id)
{
return _myModels.Where(x => x.Id == id).SingleOrDefault();
}
}
Code: Select all
public class MyEfUnitOfWork : IMyUnitOfWork
{
private readonly MyDbContext _ctx;
public IMyRepository MyModels { get; }
public MyEfUnitOfWork(MyDbContext ctx, MyEfRepository repo)
{
_ctx = ctx;
MyModels = repo;
}
void Commit() => _ctx.SaveChanges();
}
Mobile version