https://github.com/yenilikci/.net-core-entity-framework-exercises
https://github.com/yenilikci/.net-core-entity-framework-exercises
create delete entity-framework-core provider read sqlite update
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/yenilikci/.net-core-entity-framework-exercises
- Owner: yenilikci
- Created: 2020-11-02T21:10:03.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2020-11-02T21:25:55.000Z (over 5 years ago)
- Last Synced: 2025-10-09T18:07:53.413Z (9 months ago)
- Topics: create, delete, entity-framework-core, provider, read, sqlite, update
- Language: C#
- Homepage:
- Size: 7.22 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# .Net-Core-Entity-Framework-Exercises
## SQLite Provider
**Yeni Core Console projesi oluşturma:**
`dotnet new console`
**SQLite provider:**
`dotnet add package Microsoft.EntityFrameworkCore.Sqlite`
**.Net Core araçları için:**
`dotnet tool install --global dotnet-ef`
**Araç kontrolü için:**
`dotnet ef -h`
**SQLite database için:**
https://sqlitebrowser.org/
**Entity Sınıfları:**
```csharp
public class Articles
{
//Primary Key (Id veya Id yani ArticlesId)
/*opsiyonel;
[Key]
public int YaziId {get; set;}
*/
public int Id { get; set; }
[MaxLength(150)] //maksimium 150 karakter olsun
[Required] //zorunlu alan
//using System.ComponentModel.DataAnnotations;
public string Title { get; set; }
public string Text {get; set;}
}
public class Category
{
public int CategoryId {get; set;}
public string Name {get; set;}
}
```
**Context Sınıfı:**
```csharp
public class BlogContext:DbContext
//using Microsoft.EntityFrameworkCore;
{
public DbSet Articles { get; set; }
public DbSet Categories {get; set;}
//Veritabanı Ayarları
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite("Data Source=blog.db");
//veritabanını belirttik
}
}
```
**Veritabanı Oluşturma:**
Migration İşlemi :
- Önce Entity Framework Core tasarım bileşenini eklememiz lazım:
`dotnet add package Microsoft.EntityFrameworkCore.Design`
- veritabanımızı oluşturalım adım 1 - (migration oluşturma işlemi):
`dotnet ef migrations add IlkDatabase`
* oluşturulanları silmek için: `dotnet ef migrations remove`
sonuç : Migrations klasörü altında 20201102174708_IlkDatabase.cs dosyamızı oluşturdu
- veritabanımızı oluşturalım adım 2 - (migrationın uygulanması)
`dotnet ef database update`
Bu veritabanı dosyasını SQLiteBrowser ile görüntüleyebiliriz.