首页 > 数据库技术 > 详细

非构造函数方式创建DbContext实例的方法

时间:2020-08-11 14:37:06      阅读:63      评论:0      收藏:0      [点我收藏+]

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace MyProject
{
public class BloggingContextFactory : IDesignTimeDbContextFactory<BloggingContext>
{
public BloggingContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<BloggingContext>();
optionsBuilder.UseSqlite("Data Source=blog.db");

return new BloggingContext(optionsBuilder.Options);
}
}
}

非构造函数方式创建DbContext实例的方法

原文:https://www.cnblogs.com/treelie/p/13475054.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!