You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not the maintainer of this library, just a user of it, but I had a similar challenge tonight and thought I'd reveal how I got it to work in a generic fashion.
I have a very standard EF core data context
public class PbxDataContext : DbContext
{
public PbxDataContext(DbContextOptions<PbxDataContext> options) : base(options)
{}
// Standard table entity models
public DbSet<CallerIdDirectory>? CallerDirectory { get; set; }
}
Nothing too complicated.
Then as a public method to my DC I added the following function
public List<T> ExecuteTableFn<T>(string fnName) where T : class, new()
{
List<T> rows = new List<T>();
this.LoadStoredProc(fnName)
.Exec(r =>
rows = r.ToList<T>()
);
return rows;
}
NOTE the : class, new() on the end of the method signature? this is needed in order to match the signature of ToList.
Once this is added , you can use it quite simply as follows
How can I make this function generic :
return Context.LoadStoredProc("dbo.ListAll")
.AddParam("limit", 300L)
.AddParam("limitOut", out IOutParam limitOut)
.Exec(r => rows = r.ToListAsync());
The text was updated successfully, but these errors were encountered: