0

I'm using Generic repository pattern in Web API C# (.Net Framework 4.7.2) with database as postgresql. I want to call database View and stored procedure using generic repository. Note: I don't use the EDMX file.

PostgreSQL View:CREATE VIEW dashboardreport AS SELECT s.fullname, t.reportid, t.statusid, t.reportingto, t.ispendingapprovel FROM staff s JOIN report t on s.staffid=t.staffid;

generic repository:

public class Repository<T> : IRepository<T> where T : class
{
    public repoDbContext dbContext = null;
    private readonly DbSet<T> dbSet = null;

    public Repository()
    {
        this.dbContext = new repoDbContext();
        this.dbContext.Configuration.ProxyCreationEnabled = false;
        this.dbContext.Configuration.LazyLoadingEnabled = true;
        dbSet = dbContext.Set<T>();
    }

    public async Task<IEnumerable<T>> GetAll()
    {
        try
        {
            return await dbSet.ToListAsync();
        }
        catch
        {
            throw;
        }
    }}

I have to call and display the result from the view / stored procedure. Thanks in advance.

1 Answers1

0

Finally, I got the answer as work-around for it. Please find the code snippet.

public async Task<IEnumerable<T>> GetView(string viewName)
{
return await dbContext.Database.SqlQuery<T>("SELECT * FROM public." + viewName).ToListAsync();
}