简体   繁体   中英

how to execute “ExecuteSqlRawAsync” in in-memory database

I am creating unit test case using x-unit and in-memory database and i am trying to execute the below line of code

await _dbContext.Database.ExecuteSqlRawAsync(lockSql, cancellationToken);

I am getting the below error: Relational-specific methods can only be used when the context is using a relational database provider.

How do i fix this and proceed with the test case?

In-Memory Database has several issues that's why Microsoft prefers to use SQLite. In-Memory Database does not allow to run raw queries.

Ref: https://docs.microsoft.com/en-us/ef/core/miscellaneous/testing/#approach-3-the-ef-core-in-memory-database

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM