duplicates lines after update

asp.net-core entity-framework-core

Question

Sometimes, when i want edit line in table(db) , this line duplicates: the old line remains and new(edited) appears. But sometimes its work correct. Why? Thanks.

Angular request:

   this.http.put('api/data/update', JSON.stringify(this.tabl1.filter(x => x.p1 == e.key)),
    {   headers: new HttpHeaders({
        "Content-Type": "application/json"})  
    }).subscribe(data => (console.log(data)));

Controller method:

[HttpPut]
public IActionResult update([FromBody] RaschetDoppokazR1[] obj)
    {
        try
        { 
          if (obj != null)
          {
            db.RaschetDoppokazR1.UpdateRange(obj);
            db.SaveChanges();
            return Json("OK");
          }
          else return Json("null");
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
            return Json("Exception");
        }
    }
1
0
8/3/2018 3:28:55 AM

Accepted Answer

when i add new line to db , primary key there generating by the function , and if i try update line without updating my data, record will sent without primary key.

0
8/3/2018 7:23:24 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow