13. 主な対応データベース
Nugetパッケージ サポートされて
るDBエンジン
メンテナンス ビルドバージョン
Microsoft.EntityFrameworkCore.SqlServer SQL Server 2012以降 EF Coreプロジェクト 6.0
Microsoft.EntityFrameworkCore.Sqlite SQLite3.7以降 EF Coreプロジェクト 6.0
Microsoft.EntityFrameworkCore.InMemory EF Core InMemoryデータ
ベース
EF Coreプロジェクト 6.0
Microsoft.EntityFrameworkCore.Cosmos Azure CosmosDB SQLAPI EF Coreプロジェクト 6.0
Npgsql.EntityFrameworkCore.PostgreSQL PostgreSQL Npgsql開発プロジェクト 6.0
Pomelo.EntityFrameworkCore.MySql MySQL,MariaDB Pomelo Foundationプロジェクト 6.0
MySql.EntityFrameworkCore.MySql MySQL MySQLプロジェクト(Oracle) 6.0
Oracle.EntityFrameworkCore OracleDB 11.2以降 Oracle 6.0
14. Code Firstとは?
public class BloggingContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
public DbSet<Post> Posts { get; set; }
…
}
public class Blog
{
public int Id { get; set; }
public string Name { get; set; }
public IList<Post> Posts { get; } = new List<Post>();
}
public class Post
{
public int Id { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public int? BlogId { get; set; }
public Blog Blog { get; set; }
}
テーブル作成
15. データベースの作成
.NET Core CLI Visual Studio
データモデルの移行を
作成
dotnet ef migrations add [移行
名]
Add-Migration [移行名]
データベースにスキー
マを作成
dotnet ef database update Update-Database
16. DB Firstとは?
public class BloggingContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
public DbSet<Post> Posts { get; set; }
…
}
public class Blog
{
public int Id { get; set; }
public string Name { get; set; }
public IList<Post> Posts { get; } = new List<Post>();
}
public class Post
{
public int Id { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public int? BlogId { get; set; }
public Blog Blog { get; set; }
}
既存テーブル