0

Is it possible to setup type of in-memory database by Entity Framework? I need this In-Memory database correctly to be as Oracle SQL.

var options = new DbContextOptionsBuilder<MyDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;
MyDbContext context = new(options);

Background: I'm using in-memory database in my unit tests. In real code I'm connecting to Oracle SQL and in one method I check content of string in database by Entity Framework by using function:

predicateBuilder.And(user => EF.Functions.Like(user.Name, "john"))

In my unit tests working method Like as case insensitive but in real code it's working as case sensitive. I found another question and solution for that and I know that this method Like works differently for SQL/SQLite, Oracle/Postgres..

I fixed this issue but for avoiding to have similar issues I'd like to setup in memory database be same type as my real database (for me Oracle SQL)

8
  • 1
    If you're going to use Oracle in production, nothing but Oracle should be used when testing. Commented Oct 12, 2023 at 14:42
  • Agree for regression testing but for unit tests will be overkill to connect to real database. I'm using in-memory only for unit tests or in past I was using mocking EF functions. Commented Oct 12, 2023 at 14:49
  • Never mind that the in-memory database is only meant for quick unit testing. Why do you want to test Oracle syntax with Entity Framework? EF isn't a database driver, it's job is to abstract the database entirely, giving the impression of working with application objects. If you use it to execute raw SQL, something is very wrong Commented Oct 12, 2023 at 14:51
  • The collation issue you talk about isn't even a product issue. You can specify case sensitive or insensitive collations in all databases. The default in Oracle is case-sensitive. The default in SQL Server is case-insensitive Commented Oct 12, 2023 at 14:52
  • 1
    The in-memory provider simply doesn't support case sensitivity, along with any other relational concept. It's just a wrapped Dictionary<string,T>. It's meant to mock the database in unit tests, not emulate it. If you want to test case sensitivity use the SQLite provider in in-memory mode. If you want faithful replication of Oracle, use a test version of Oracle. Unit testing doesn't mean you shouldn't use a database when you need to test database behavior Commented Oct 12, 2023 at 14:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.