Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

wpf repository pattern query async with includes properties

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);
}
Comment

wpf repository pattern query async with includes properties

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;
    }
}
Comment

wpf repository pattern query async with includes properties

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;
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# variable 
Csharp :: LINQ return list of unique values with counts 
Csharp :: Process.Start(osk.exe) 
Csharp :: c# increment by 2 
Csharp :: asp.net core web api Microsoft.Data.SqlClient.SqlException (0x80131904): 
Csharp :: call Textboxfor in cs 
Csharp :: how to add an embedded resource in visual studio code 
Csharp :: ef core save keyless entity 
Csharp :: how to change the volume of all sound effects in monogame 
Csharp :: c# encrypt folder SHA512 
Csharp :: Modify middleware response c# .net 
Csharp :: quine in c# 
Csharp :: c# delegates 
Csharp :: C# walk down a tree and back 
Csharp :: snakes and ladder single player c# 
Csharp :: windowsform mail sender app 
Csharp :: reference variable from another script "winforms" c# 
Csharp :: edit pdf itextsharip 
Csharp :: Get dwgexport setting reivit api 
Csharp :: wpf user parent controller datacontext 
Csharp :: show in editor unity 
Csharp :: c# Color Convert 
Csharp :: c sharp if statements 
Csharp :: how to disable button until the value is selected c# 
Csharp :: dotcms contentidentifier 
Csharp :: can a dictionary type use get set c# 
Csharp :: does Registry.CurrentUser.OpenSubKey create the key if it does not exist? 
Csharp :: remove last character from stringbuilder c# 
Csharp :: c# SQLite execute Command 
Csharp :: serenity.is required field 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =