f7q / learning

NET Core learning Github
Other
0 stars 1 forks source link

EnitityFrameworkCore学習 #39

Open f7q opened 7 years ago

f7q commented 7 years ago
f7q commented 7 years ago

ScaffoldはVisual Studio上からの作業になりそう。

f7q commented 7 years ago
  1. db.sqliteを製造する。
  2. dotnet new -t Web
  3. project.jsonMicrosoft.EntityFrameworkCore.Sqlite.Desinの追加
  4. dotnet restore
  5. dotnet build
  6. 実行ファイルがある場所にdb.sqliteを置く
  7. dotnet ef dbcontext scaffold "Data Source=db.sqlite" Microsoft.EntityFrameworkCore.Sqlite -o Models
    実行するとModelsフォルダにフォルダが製造される。

恐らく、最小限の実行ファイルさえあればModelとクラスは製造されるはず。

f7q commented 7 years ago

SQLServer Localの仕組みが不明になってきている。
マイグレーション失敗する。

sqllocaldb -i コマンド群を活用

f7q commented 7 years ago

.NET Core 2.0からSystem.Transaction.TransactionScopeが実装予定

f7q commented 6 years ago

using System.Collections.BitArray型 = bytea型、boolean型にはならない

f7q commented 6 years ago

Npgsql.EntityFrameworkCore.PostgreSQL

modelBuilder.Entity<Chassis>().UseXminAsConcurrencyToken();

楽観ロックのカラム追加

modelBuilder.Entity<Chassis>(b =>
{
    b.Property<uint>("xmin")
        .HasColumnType("xid")
        .ValueGeneratedOnAddOrUpdate()
        .IsConcurrencyToken();
});

コメント追加

modelBuilder.Entity<MyEntity>().ForNpgsqlHasComment("コメント")

f7q commented 6 years ago

仕様

f7q commented 6 years ago

EF Core2で実行したSQLの引数をログに出力する

public class AppContext : DbContext
{
  protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
  {
    // この設定により引数のログが出力される
    optionsBuilder.EnableSensitiveDataLogging();
  }
}