EFCore Context Creation Without Dependency Injection

2019年11月18日 12点热度 2人点赞 0条评论
内容目录

For context classes, there should be an overloaded base(options) constructor.

    public partial class DatabaseContext : DbContext
    {
        public DatabaseContext()
        {
        }
    public DatabaseContext(DbContextOptions<DatabaseContext> options)
        : base(options)
    {
    }

}

Usage

            var optionsBuilder = new DbContextOptionsBuilder<DatabaseContext>();
            optionsBuilder.UseSqlite("filename=C:\666.db");
            DatabaseContext context = new DatabaseContext(optionsBuilder.Options);

痴者工良

高级程序员劝退师

文章评论