No mapping exists from object type System.Collections.Generic.List when executing stored proc with parameters in EF 4.3

后端 未结 7 1389
旧巷少年郎
旧巷少年郎 2020-12-30 19:30

Lately I\'ve been working on stored procedure and encountered 1 strange problem.

First, I was able to successfully call a stored procedure from the database via:

7条回答
  •  伪装坚强ぢ
    2020-12-30 20:08

    The solution for this problem (in my case was)

     var stuff = db.Database.SqlQuery(query, parms);
    

    Where query was a string that had parameters inserted such as @Name etc. The parms variable was a List of SQLParameters. SQL doesn't like generic lists....

    SQL must have an array of SQLParameters sent as and object[] and not a list of generic type.

    var stuff = db.Database.SqlQuery(query, parms.ToArray());
    

提交回复
热议问题