“WPF Repository Pattern Query Async with CLASTING PROPERTI” Kode Jawaban

WPF Repository Pattern Query Async with CLASTING PROPERTI

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 Query Async with CLASTING PROPERTI

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 Query Async with CLASTING PROPERTI

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

Jawaban yang mirip dengan “WPF Repository Pattern Query Async with CLASTING PROPERTI”

Pertanyaan yang mirip dengan “WPF Repository Pattern Query Async with CLASTING PROPERTI”

Lebih banyak jawaban terkait untuk “WPF Repository Pattern Query Async with CLASTING PROPERTI” di C#

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya