> 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/entity-ve-context-classlarinin-olusturulmasi.md).

# Code First - Entity ve Context Classlarının Oluşturulması

Entity class ları veri tabanımızdaki tablolara karşılık gelir. Context ise veri tabanı ile bağlantıyı sağlayan bir classtır. CRUD işlemleri buradan yürütülür. İlk bölüm Code First ile oluşturuldu.

```aspnet
// Entity

public class Product
{
    public int Id { get; set; }
    public string Name { get; set; }
    public decimal Price { get; set; }   
}

public class Category
{
    public int Id { get; set; }
    public string Name { get; set; }  
}
```

{% hint style="warning" %}
Foreign Key leri direk Id yazarak yada class isminin sonuna Id ekleyerek (ProductId) oluşturulabilir. Ancak bunlarda farklı bir tanımlama yapmak istersek **"Data Annotations"** kullanılmalıdır.&#x20;

```aspnet
public class Product
{
    [Key]
    public int proid { get; set; }  
}
```

{% endhint %}

```aspnet
public class ShopContext:DbContext
{
    public DbSet<Product> Products { get; set; }
    public DbSet<Category> Categories { get; set; }
}
```
