I seem to be having a problem with my model not updaing, but it seems there is only one aspect that.
I have the following setup
public class Stages
{
public int ItemNumber {get; set;} <-- seems to be updating correctly
public string ItemName {get; set;} <-- seems to be updating correctly
public int ItemStage {get; set;} <-- always results in 0
}
public interface IStageRepository
{
List<Stages> GetAll();
}
public class StageRepository : IStageRepository
{
private IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["StagesConnection"].ConnectionString);
public List<Stages> GetAll()
{
return this.db.Query<Stages>("SELECT * FROM Stages_vw").ToList();
}
}
Under my HomeController I have the following
IStageRepository stagesRepo = new StageRepository();
public ActionResult Index()
{
return (stagesRepo.GetAll());
}
Here is the schema of the view
TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME COLUMN_DEFAULT
WebServices dbo Stages_vw ItemNumber NULL
WebServices dbo Stages_vw ItemName NULL
WebServices dbo Stages_vw Stage NULL
If I do a "SELECT * FROM Stages_vw" in SSMS the results are correct
I have stumbled across these posts but I am feeling a little confused any help would be greatly appreciated
ANSWER per @chipples
This was due to a column name in the view not matching
As per the comments, the problem is that the names on your model and in your database do no match (ItemStage in the model, Stage in the DB). Dapper requires the names to match in order to map automatically. You should either rename the property on your model to Stage, or use an alias in your SQL ("SELECT Stage AS ItemStage...").