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.

// 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; }  
}
public class ShopContext:DbContext
{
    public DbSet<Product> Products { get; set; }
    public DbSet<Category> Categories { get; set; }
}

Last updated

Was this helpful?