小编jac*_*srt的帖子

如何测试DbContext是否在内存中?

我使用.Net Core 2.1.我的应用程序使用Entity Framework Core,并具有CoreDbContext从派生的上下文DbContext

对于单元测试,我使用的内存版本CoreDbContext,从而在我的代码中产生了此代码Startup.cs

if (useInMemoryDatabase)
{
    services.AddDbContext<CoreDbContext>(options => 
           options.UseInMemoryDatabase("dbname"));
}
else
{
    services
      .AddDbContext<CoreDbContext>(options => 
           options.UseSqlServer(DefaultDbConnectionString));
}
Run Code Online (Sandbox Code Playgroud)

我也有通过上下文访问数据库的方法。这些有时有时需要知道上下文是否在内存中,因为内存上下文的行为与普通上下文不同:

void AddRecordX(CoreDbContext context)
{
    bool contextIsInMemory = .....;

}
Run Code Online (Sandbox Code Playgroud)

如何测试上下文是在内存中还是与真实对象相关联SQL Server database

entity-framework entity-framework-core entity-framework-core-2.1

4
推荐指数
1
解决办法
1120
查看次数

如何将字符串联合类型中的所有字符串组成一个数组?

type stringUnion = "Value1"|"Value2" 我想从所有字符串中获取并创建一个数组stringUnion

所以数组看起来像这样["Value1","Value2"],我想要一个数组,这样我就可以像这样迭代它:

theArray.map((current, index)=>{

})
Run Code Online (Sandbox Code Playgroud)

我怎么做?

types typescript

4
推荐指数
1
解决办法
2962
查看次数