“WPF Repository Pattern Consulta Async com Inclui Propriedades” Respostas de código

WPF Repository Pattern Consulta Async com Inclui Propriedades

public T Get(int id, params Expression<Func<T, object>>[] includes)
{
    IQueryable<T> query = _context.Set<T>();
    if (includes != null)
        foreach (Expression<Func<T, object>> include in includes)
            query = query.Include(include);

    return ((DbSet<T>)query).Find(id);
}
Confused Cobra

WPF Repository Pattern Consulta Async com Inclui Propriedades

public interface IGenericRepository<TEntity> where TEntity : class
{
    Task<TEntity> Get(int id, string[] paths = null);
}

public class GenericRepository<TEntity> : IGenericRepository<TEntity> where TEntity : class
{
    private readonly ApplicationDbContext _context;
    private readonly DbSet<TEntity> _dbSet;

    public GenericRepository(ApplicationDbContext context)
    {
        _context = context;
        _dbSet = _context.Set<TEntity>();
    }

    public async Task<TEntity> Get(int id, string[] paths = null)
    {
        var model = await _dbSet.FindAsync(id);
        foreach (var path in paths)
        {
            _context.Entry(model).Reference(path).Load();
        }
        return model;
    }
}
Confused Cobra

WPF Repository Pattern Consulta Async com Inclui Propriedades

public interface IGenericRepository<TEntity> where TEntity : class
{
    Task<TEntity> Get(int id, string[] paths = null);
}

public class GenericRepository<TEntity> : IGenericRepository<TEntity> where TEntity : class
{
    private readonly ApplicationDbContext _context;
    private readonly DbSet<TEntity> _dbSet;

    public GenericRepository(ApplicationDbContext context)
    {
        _context = context;
        _dbSet = _context.Set<TEntity>();
    }

    public async Task<TEntity> Get(int id, string[] paths = null)
    {
        var model = await _dbSet.FindAsync(id);
        foreach (var path in paths)
        {
            _context.Entry(model).Reference(path).Load();
        }
        return model;
    }
}
Confused Cobra

Respostas semelhantes a “WPF Repository Pattern Consulta Async com Inclui Propriedades”

Perguntas semelhantes a “WPF Repository Pattern Consulta Async com Inclui Propriedades”

Mais respostas relacionadas para “WPF Repository Pattern Consulta Async com Inclui Propriedades” em C#

Procure respostas de código populares por idioma

Procurar outros idiomas de código