Using .FromSql to run Stored Precedure in EntityFrameworkCore 2

c# entity-framework-core

Question

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?

1
0
4/12/2018 8:32:21 AM

Popular Answer

List<SqlParameter>() will not work for passing parameter to StoredProcedure. You better use SqlParameter[] (array of SqlParameter).

2
4/12/2018 8:48:56 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow