question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

EF Core 3.1 Beta 2: Slower performance when using Date data type

See original GitHub issue

I can’t find the link to Oracle forum anymore (and anyway, I find them pretty not user friendly), so I’ll post my issue here. As I said in my previous post, I’m experiencing major performance degradation (or simply an issue) when using dates.

I have the following query:

var doorCrossings = await _oracleContext
    .DoorCrossings
    .AsNoTracking()
    .Where(dc => dc.Matricule == user.Matricule && dc.CrossingAt.Date == date.Date)
    .OrderBy(dc => dc.CrossingAt)
    .ToListAsync();

Note that I’m using the “Date” property of the dates because I don’t want to take the time into account.

The “Matricule” field is “varchar2(16)” and “CrossingAt” is a “Date”. There is an index in the table based in these two fields. When running this query in the .NET 2.2 version, it is very fast (1-3s, there are millions of lines in this table).

However, when running the exact same query on the exact same database with the version 3.1 of the provider, the query execution never ends. I put a break point to the next line and it never gets hit and I don’t see any exception in the output.

To help investigating, I put the logging level to “Information”. When doing it with the 2.2 version, I see the query but I don’t see it with the 3.1 version. I tried removing the second part of the condition and then, I see the logs (I don’t get the results but there is no index on the “Matricule” field alone so it can be that it takes a long time to execute).

The part date of the generated query in 2.2 is

AND ("TRUNC"(FIELD) = :date_Date_1)

I replaced the real name of the field by “FIELD” for confidentiality reason.

So I don’t know how to investigate this further but it seems that there is an issue with dates.

_Originally posted by @ssougnez in https://github.com/oracle/dotnet-db-samples/issues/49#issuecomment-660342024_

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
alexkehcommented, Aug 13, 2020

This issue is resolved.

Explanation: If the EF Core model does not accurately indicate which string properties are and are not Unicode, performance can become significantly degraded, including queries undertaking full scans. When the provider scaffolds the model, this problem shouldn’t happen. When the mapping is manually created or the scaffolded model is modified, this performance problem may occur.

To avoid the problem, one can either:

  • Use scaffolding to generate the entity classes corresponding to the database tables. The correct fluent API for each of the columns in the table will be generated.
  • If manually creating the entity classes corresponding to the database tables, then correctly map each string entity property to the correct column type, especially when identifying whether the data type uses Unicode or not.

For example: By default, the .NET String entity type maps to Oracle NVARCHAR2. If the column type in the database is VARCHAR2, then the IsUnicode(false) or HasColumnType(“VARCHAR2”) fluent API should be used to correctly map the string entity property to VARCHAR2 database type.

0reactions
alexkehcommented, Aug 13, 2020

No problem @ssougnez. Glad we could help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Entity-framework code is slow when using Include() many ...
Question about EF Core, is the cartesian explosion worse performance wise? I mean, is the rule of thumb of 3 includes before splitting...
Read more >
Entity Framework Core performance : r/dotnet
I am using Entity Framework Core for my first 'big' project but a senior developer told me that EF really slows down your...
Read more >
Efficient Querying - EF Core
Performance guide for efficient querying using Entity Framework Core.
Read more >
How to improve data access performance in EF Core
Take advantage of these 10 strategies to improve data access performance when using Entity Framework Core in your data-driven .NET applications.
Read more >
Using Entity Framework (EF) with .NET Core 3.1 | Db2
Hi,Anyone around here have any experience using EF 3.1 with DB2 Connect? ... 2) If IBM would release database drivers for their own...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found