admin管理员组文章数量:1335612
I have my own framework that I've been working on for years. It has an AppSecurity
project that handles users, roles, permissions, etc. For it, I created an EF Core code-first DbContext
class:
internal class AppSecurityDataContext : DbContext
{
private string _connectionString = @"Server=mysite;Database=TheLastAppIWorkedOn;User Id=abc1;Password=xyx2;";
public AppSecurityDataContext()
{
}
public AppSecurityDataContext(string connectionString)
{
_connectionString = connectionString;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(_connectionString);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<UserEntity>().HasData
(
new UserEntity
{
// Properties set here
}
);
}
}
Right now I'm working on a WPF app called Falcon. It has its own DbContext which manages the Falcon DB objects. Right now, the connection string for it is stored in the DbContext class becuase I'm not sure how this is supposed to be done.
private string _connectionString = @"Server=mysite;Database=Falcon;User Id=someone;Password=somepwd;";
public FalconDataContext()
{
}
public FalconDataContext(string connectionString)
{
_connectionString = connectionString;
}
public FalconDataContext(DbContextOptions<FalconDataContext> options) :
base(options)
{
}
Next week, I could be in another app that needs to use AppSecurity
. Herein lies the problem - when I work on other apps that use the AppSecurity
project, I have to open its DbContext
class, change the connection string, then open Package Manager and rebuild.
So, how can my AppSecurity
project get the connection string the other project I'm working?
本文标签: Entity Framework Core codefirst connection string for multiple repositoriesStack Overflow
版权声明:本文标题:Entity Framework Core code-first connection string for multiple repositories - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742385286a2464906.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论