[英]How do I fix this error? Argument 1: cannot convert 'string' to 'Microsoft.EntityFrameworkCore.DbContextOptions'
I have a problem with DbContext
.我对
DbContext
有疑问。 I decided to make a new class, which will be responsible for the connections with the Database.我决定创建一个新的 class,它将负责与数据库的连接。
public class DataContextService : IDataContextService
{
private IMediator _mediator { get; }
private CommonContext _commonContext { get; set; }
private MembershipContext _membershipContext { get; set; }
private LogsContext _logContext { get; set; }
private MongoContext _mongoContext { get; set; }
private IServiceScopeFactory _scopeService;
However, I have an exception near the name of base:但是,我在 base 名称附近有一个例外:
Argument 1: cannot convert 'string' to 'Microsoft.EntityFrameworkCore.DbContextOptions'.
参数 1:无法将“字符串”转换为“Microsoft.EntityFrameworkCore.DbContextOptions”。
I found a similar issue and response with code similar to mine, but I am not sure how to fix this issue.我发现了一个类似的问题和响应,代码与我的类似,但我不确定如何解决这个问题。 I would appreciate your help.
我将不胜感激你的帮助。
internal MembershipContext Membership_Context
{
get
{
if (_membershipContext == null)
{
//This is where the error happens
_membershipContext = new MembershipContext(AwsSecretsManager.Get(AwsSecretNames.DbsMembership, "BusinessObjects"));
}
return _membershipContext;
}
}
I found how to fix the error.我找到了如何修复错误。 I was missing the definition for
DBContextOptions
inside the MembershipContext
.我缺少
MembershipContext
中DBContextOptions
的定义。 I just had to add it so that the method could recognize the connection string.我只需要添加它,以便该方法可以识别连接字符串。
Inside MembershipContext.cs
:在
MembershipContext.cs
:
private static DbContextOptions GetOptions(string connectionString)
{
return SqlServerDbContextOptionsExtensions.UseSqlServer(new DbContextOptionsBuilder(), connectionString, o => o.CommandTimeout(300)).Options;
}
public MembershipContext(string connectionString) : base(GetOptions(connectionString))
{
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.