using System;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

namespace EntityFrameworkCoreSample.Models
{
    public class BloggingContext : DbContext
    {
        public BloggingContext(DbContextOptions<BloggingContext> options) : base(options)
        {
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            //modelBuilder.Entity<Blog>().HasQueryFilter(blog => !blog.IsDeleted && blog.Posts.All(post => !post.IsDeleted));

            //modelBuilder.Entity<Payment>().HasQueryFilter(b => !b.IsDeleted);

            modelBuilder.Entity<Payment>().HasQueryFilter(b => !b.IsDeleted);

            base.OnModelCreating(modelBuilder);
        }

        public virtual DbSet<Blog> Blogs { get; set; }

        public virtual DbSet<Post> Posts { get; set; }

        public virtual DbSet<Payment> Payments { get; set; }

        public virtual DbSet<WeChatPayment> WeChatPayments { get; set; }

        public virtual DbSet<AlipayPayment> AlipayPayments { get; set; }

    }
}
