I am new in ASP.net MVC (I am using asp 5 mvc 6)
So I want to use stored procedures and I found that Dapper-dot-net is solution.
I created model that stored procedure 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; }
}
}
And I created .cs file for commands
public class ArticleAccess
{
private IDbConnection db = Connection.GetConnection();
public List<ArticleGetAll> GetAll()
{
string procedureName = "usp_ArticleGetAll";
return db.Query<ArticleGetAll>(procedureName).ToList();
}
}
And I wanted to create VIEW from model, I get this error Error 1
And how DbContext need to look? Do I need DbContext for Dapper?
I have class Connection.cs that I use to open SQL Connection
namespace WebCMS.Dapper
{
public class Connection
{
public static SqlConnection GetConnection()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
con.Open();
return con;
}
}
}
Should I put :DbContext in this class and add DB Sets?
If you check Dapper documentation for stored procedures then you will see that they are using argument commandType
for that:
var user = cnn.Query<User>("spGetUser", new {Id = 1},
commandType: CommandType.StoredProcedure).SingleOrDefault();
I think this should solve your problem. The error message is very strange, because DbContext
is not related to Dapper in any way.