Genesys Source

How-to Fix EF Core 2.0 No mapping to a relational type can be found for the CLR type List<SqlParameter>

Fix: EF Core 2.0 “No mapping to a relational type can be found for the CLR type List<>”

Entity Framework Core 2.0 (EF 7) contains a great .FromSql(string storedProc, object[] params) method, except for the fact that passing in a List<SqlParameter> results in a runtime error:

No mapping to a relational type can be found for the CLR type List<SqlParameter>

The fix: Convert List<> to Array via .ToArray()

            var myId = 1;

            var procedure = "MyStoredProc";           

            var parameters = new List<SqlParameter>()

            {

                new SqlParameter("@Id", myId)

            };

            var results = db.Data.FromSql(procedure, Parameters.ToArray());

 

Happy Coding!

Leave your comment