Please refer to this picture:
This table data are fetched with Entity Framework. When I double click the EmailID
and change it, the data will be updated to SQL Server automatically.
Here it's web api code about update:
// 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;
}
}
}
When this code run, the modified emailID
has been updated to SQL Server, no need any sql state, no need ID
, how it update the code?
AngularJS controller:
$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.')
})
};
Angular Service:
this.updateSubscriber = function (sub) {
return $http({
method: 'put',
data: sub,
url: 'api/Subscriber'
});
}
Hope some one could help me explain it.
It looks like every row subscribe to a wep API function. The function uses Angular JS to make async call to your code behind.
Then, ain't no magic here :
myEntity.Entry(sub).State = EntityState.Modified;
try
{
myEntity.SaveChanges();
}
Sub contain informations about what has been modified on your entity.
Once db.SaveChages()
is reached, it looks for what modifications should be made in your db, there is only one at the time so it's probably very fast.
Entity Framework write it's own db query on the backend, you can't see them unless you use a profiler.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments