Good day,
I am having an issue using the .FromSqlRaw as it it returning an Unhandled Exception: InvalidOperationException: No mapping to a relation type can be found for the CLR type ;object[]'. While this might sound simple, I am passing the stored procedure string and the parameters to the .FromSqlRaw.
So the following is what is throwing the error:
public async Task<List<MyClass>> LoadDataAsync<U>(string storedProcedure, U parameter)
{
var optionsBuilder = new DbContextOptionsBuilder<DbContext>().UseSqlServer(Configuration.GetConnectionString("Default"));
using DbContext dbContext = new DbContext(optionsBuilder.Options))
{
List<MyClass> myClass = await dbContext.MyClass.FromSqlRaw(storedProcedure, parameters).ToListAsync();
return myClass;
}
}Now I am passing the following into that:
public async Task<IList<MyClass>> GetIdAsync(string name, string normalName, DateTime createdDate)
{
var output = await _sql.LoadDataAsync<object>("[dbo].[GetDBId] @p0, @p1, @p2", new [] { name, normalName, createdDate });
return output;
}I know the stored procedure works, because if I Execute that stored procedure with the same values from SQL Server Management Studio it displays the correct output. So I know the issue with with the input the stored procedure and the .FromSqlRaw not liking
how I pass the information to it. I had tried _sql.LoadDataAsync<dynamic> before but it too errored out. In this case I am passing three objects but some of my stored procedures have upwards of 18 parameters, so I need that LoadDataAsync to be able to accept
any number of parameters.
If anyone has a thought on what might help I would appreciate it.