0
請參照這樣的畫面:如何實體框架的工作
本表數據獲取與實體框架。當我雙擊EmailID
並進行更改時,數據將自動更新爲SQL Server。
這的Web API代碼有關更新:
// PUT: api/Subscriber/5
public void Put(tbl_Subscribers sub)
{
if (ModelState.IsValid)
{
myEntity.Entry(sub).State = EntityState.Modified;
try
{
myEntity.SaveChanges();
}
catch (Exception)
{
throw;
}
}
}
當這個代碼運行,修改後的emailID
已經更新到SQL Server,無需任何SQL狀態,無需ID
,它如何更新的代碼?
AngularJS控制器:
$scope.updSubscriber = function (sub, eve) {
sub.MailID = eve.currentTarget.innerText;//get EmailID
var upd = APIService.updateSubscriber(sub);//update EmailID
upd.then(function (d) {
getAll();
}, function (error) {
console.log('Oops! Something went wrong while updating the data.')
})
};
角服務:
this.updateSubscriber = function (sub) {
return $http({
method: 'put',
data: sub,
url: 'api/Subscriber'
});
}
希望有人能幫我解釋一下。
'它如何更新代碼'<=我不理解你的問題。它是什麼,你想要做的確切...... – Igor
請參閱截圖。 – qianli
從'put'方法返回更新模型,然後從結果角度更新模型。 – Igor