.NET5.0 Ensure that the return type can be mapped by the current provider

215 Views Asked by At

Model:

public partial class FN_Result
{
    public string UserImage { get; set; }
    public string UserName { get; set; }
    public string Title { get; set; }
    public int messageId { get; set; }
    public int SenderId { get; set; }
    public int ReceiverId { get; set; }
    public string MessageText { get; set; }
    public bool MessageStatus { get; set; }
    public bool IsAdmin { get; set; }
    public bool IsClinician { get; set; }
    public string CreatedOn { get; set; }
    public int RowNum { get; set; }
}

Constructor and variable declaration:

private readonly IDbConnection db;

public DbContext(DbContextOptions<DbContext> options, IConfiguration configuration)
            : base(options)
{
    this.Configuration = configuration;
    this.db = new SqlConnection(this.Configuration.GetConnectionString("PortalDb"));
}

We have the following DbFunction in an MVC project .NET 5.0

[DbFunction("namespace", "FN_Name")]
public async Task<IEnumerable<FN_Result>> FN_MethodName(int id)
{
   var parameters = new DynamicParameters();
   parameters.Add("@id", id);

   return await this.db.QueryAsync<FN_Result>("[namespace].[FN_Name](@id)", parameters, commandType: CommandType.Text);
}

IEnumerable<FN_Result> is indeed the return type of db.QueryAsync<FN_Result>

However it's throwing the following error message: Message=The DbFunction 'dbPortalContext.FN_Name([System.Int32, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e])' has an invalid return type 'Task<IEnumerable<FN_Result>>'. Ensure that the return type can be mapped by the current provider.

We have also tried converting it into a List, to no avail

0

There are 0 best solutions below