1

I am using Entity Framework to access an Oracle Database. I have an entity with a property called "AOID". The the mapping file for this entity, I have the following rules applied (notice the IsRequired):

this.Property(t => t.Aoid)
                .IsRequired()
                .HasMaxLength(25);

However, when I run a SQL Profiler report or an AWR report, a query keeps showing up with the following where clause:

WHERE ((((UPPER("Extent2"."AOID")) = (UPPER(:p__linq__0))) OR ((UPPER("Extent2"."AOID") IS NULL) AND (UPPER(:p__linq__0) IS NULL)))

Why is entity framework adding the NULL checks to the where clause when the property is marked as required? These NULL checks are preventing the indexes from being used properly.

jkruer01
  • 2,175
  • 4
  • 32
  • 57
  • Some databases like SQL server require that separate check for equality (eg see http://stackoverflow.com/questions/1843451/why-does-null-null-evaluate-to-false-in-sql-server), but I don't think it should be required for Oracle. I would try setting `UseCSharpNullComparisonBehavior = false` per http://stackoverflow.com/questions/26920479/can-i-use-usecsharpnullcomparisonbehavior-for-a-single-query – rmc00 Aug 12 '16 at 19:17
  • But if the column in the database is NOT NULL then why would it even bother to check? – jkruer01 Aug 12 '16 at 19:31
  • 1
    As I understand it, when UseCSharpNullComparisonBehavior is true (the default value), EF makes the determination about null checks based on the C# type. So if AOID is a string or some nullable type, then it would add the check. When you set it to false, then EF makes a decision based on the database, which should remove the null check in Oracle's case. – rmc00 Aug 12 '16 at 19:54
  • I will try this and see if it fixes the issue. – jkruer01 Aug 12 '16 at 19:55

0 Answers0