I need to run a stored procedure on my MSSQL Db through EntityFrameworkCore 2. I have the following method;
public IList<Trader> GetTradersWithinRadius(int category, decimal latitude, decimal longitude)
{
var sproc = "FindTradersWithinRadius";
var sqlParams = new List<SqlParameter>()
{
new SqlParameter("@CATEGORY", category),
new SqlParameter("@LATITUDE", latitude),
new SqlParameter("@LONGITUDE", longitude),
};
var parameters = sqlParams.ToArray<object>();
return this.Traders.FromSql($"{sproc} @CATEGORY, @LATITUDE, @LONGITUDE", sqlParams).ToList();
}
However EF is giving the following error when running?
No mapping to a relational type can be found for the CLR type
List<SqlParameter>
Can anyone tell me what I am doing wrong here please?
List<SqlParameter>()
will not work for passing parameter to StoredProcedure
. You better use SqlParameter[]
(array of SqlParameter
).