Dapper 存储过程和视图

Dapper Stored procedure and View

我是 ASP.net MVC 的新手(我正在使用 asp 5 mvc 6)

所以想用存储过程,发现Dapper-dot-net是解决方案

我创建了存储过程的模型returns

    namespace WebCMS.Dapper
   {
    public class ArticleGetAll
    {
        public int ArticleID { get; set; }
        public string Title { get; set; }
        public string Cotent { get; set; }
        public DateTime DateCreated { get; set; }
        public string Username { get; set; }
    }
}

我为命令创建了 .cs 文件

    public class ArticleAccess
   {
    private IDbConnection db = Connection.GetConnection();

    public List<ArticleGetAll> GetAll()
    {
        string procedureName = "usp_ArticleGetAll";
        return db.Query<ArticleGetAll>(procedureName).ToList();

    }
}

我想从模型创建 VIEW,但出现此错误 Error 1

DbContext 需要怎么看? Dapper 需要 DbContext 吗?

我有 class Connection.cs 用于打开 SQL 连接

    namespace WebCMS.Dapper
{
    public class Connection
    {
        public static SqlConnection GetConnection()
        {
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
            con.Open();

            return con;
        }
    }
}

我应该把 :DbContext 放在这个 class 中并添加数据库集吗?

如果您查看 stored procedures 的 Dapper 文档,您会发现他们为此使用了参数 commandType

var user = cnn.Query<User>("spGetUser", new {Id = 1}, 
    commandType: CommandType.StoredProcedure).SingleOrDefault();

我认为这应该可以解决您的问题。错误信息很奇怪,因为 DbContext 与 Dapper 没有任何关系。