> For the complete documentation index, see [llms.txt](https://cnahmet.gitbook.io/asp-net-notlarim/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cnahmet.gitbook.io/asp-net-notlarim/orm-entity-framework-core/veri-tabanindan-kayit-guencelleme.md).

# Veri Tabanından Kayıt Güncelleme

#### Tek kayıt güncelleme

```
static void UpdateProduct() 
{            
    using(var db = new ShopContext())
    {
        var p = db
        .Products
        .Where(i=>i.Id ==1)
        .FirstOrDefault();
        if(p != null)
            {
            p.Price *= 1.2m;
            db.SaveChanges();
            }
    }
}
```

{% hint style="danger" %}
Aynı kayıt üzerinde tekrar güncelleme yapılmasını istemiyorsak **`.AsNoTracking()`** kullanılır.
{% endhint %}

{% hint style="info" %}
Sql sorgusu yazmadan kayıt güncellemek için

```
static void UpdateProduct() 
{            
    var entity = new Product(){Id=3};
    db.Products.Attach(entity);
    entity.Price = 600;
    db.SaveChanges();
}
```

{% endhint %}

#### Çoklu kayıt güncelleme

```
static void UpdateProduct() 
{            
    var p = db
    .Products
    .Where(i=>i.Id == 4)
    .FirstOrDefault();

    if(p != null)
        {
        p.Price = 4000;
        p.Name = "Microsoft Surface";
        db.Products.Update(p);
        db.SaveChanges();
        }
}
```
