.EDMX
<Property Name="uid" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
EF had set the StoreGeneratedPattern = "Identity", but why I still cannot save into db? Debug show that the value are always 0, guess is quite correct as server not return the value to the web before inserting, but model validate always false, and I had go through C#, entity framework, auto increment and Autonumber with Entity Framework but no luck, what am I doing wrong? Any idea?
Update 1:
Added model and meta data picture, forgot to mention that Im using EF DB first to generate the class
ASP.NET MVC View
<div class="editor-field">
@Html.HiddenFor(model => model.uid)
</div>
ASP.NET MVC Controller
[HttpPost, ValidateJsonAntiForgeryToken]
public JsonResult Create(BasicUserInfo basicuserinfo)
{
if (ModelState.IsValid)
{
db.BasicUserInfoes.Add(basicuserinfo);
db.SaveChanges();
}
else
{
return Json(new { valid = "N", err = CaptureError() });
}
return Json(new { valid = "Y", route = Url.Action("Index") });
}
Script
var self = this;
var data = "";
var _model = new model();
var data = JSON.stringify({ "BasicUserInfo": $(e.currentTarget).serializeObject() });
var _Create = new Create();
_Create.fetch({
type: 'POST',
headers: headers,
data: data,
contentType: "application/json; charset=UTF-8",
success: function (data, textStatus, jqXHR) {
if (textStatus.valid == "Y") {
_model.AppendAddSuccess(textStatus.route);
} else {
_model.AppendFailed(textStatus.err);
}
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(textStatus.statusText);
}
});
SQL Server 2008
Error
Modal
MetaData