Parameter out of range on db.SaveChanges () in EF
I am developing an MVC application with Entity Framework. I am using the first database approach and there is a numeric field in my database:
[N15] NUMERIC (1, 1) NULL,
My code where I am getting the error:
public ActionResult allsave(VchrViewModel v)
{
List<TrD> chklist = this.dt;
if (br.vchrbalance(chklist) == true)
{
trm = v.master;
trm.S100 = vt;
var n = db.TrMs.Max(x => x.N100);
trm.N100 = n + 1;
trm.S104 = getmonth(trm.D1.ToString());
trm.S103 = getyear(trm.D1.ToString());
db.TrMs.Add(trm);
db.SaveChanges();
seid = 0;
var s = this.dt;
foreach (TrD trd in s)
{
trd.S100 = vt;
var d = db.TrDs.Max(x => x.N100);
trd.N100 = d + 1;
trd.N101 = v.master.N100;
db.TrDs.Add(trd);
db.SaveChanges();
TrnYes4MST(trd.S1);
}
return Json(new { msg = "Y" });
}
else
{
return Json(new { msg = "N" });
}
}
I am getting records for two different tables from a view. I have successfully saved a record in the first table named "TrM" which is irrelevant for N15. But in foreach loop for table "TrD" for first iteration N15 = 1. But by db.SaveCHanges () method I get following error.
Parameter {1.0} is out of range
I restored the edmx file but couldn't solve it.
source to share
The problem was EDMX. Only changes to the database prevent it from working. Since the EDMX does not update itself with changes in the database, so every time you make changes to the database, you need to update the EDMX from Visual Studio.
I updated the design of my table in SQL Server and then updated the EDMX. After that I run the Custom Tool on my Model.tt file ... And it works !!!
source to share