-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Description
await using var ctx = new BlogContext();
await ctx.Database.EnsureDeletedAsync();
await ctx.Database.EnsureCreatedAsync();
ctx.Blogs
.ExecuteDelete();
public class BlogContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseSqlServer(@"Server=localhost;Database=test;User=SA;Password=Abcd5678;Connect Timeout=60;ConnectRetryCount=0;Encrypt=false")
.LogTo(Console.WriteLine, LogLevel.Information)
.EnableSensitiveDataLogging();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Blog>(
x => x.Navigation(b => b.Details).AutoInclude());
}
}
public class Blog
{
public int Id { get; set; }
public string? Name { get; set; }
public BlogDetails Details { get; set; }
}
public class BlogDetails
{
public int Id { get; set; }
public int Foo { get; set; }
}
Split off from #29992