- dotConnect for Oracle 9.5.429
- EF Core 2.0.1
- .Net Core 2.0.0
Code: Select all
class Program
{
static void Main(string[] args)
{
var config = OracleEntityProviderConfig.Instance;
config.QueryOptions.UseCSharpNullComparisonBehavior = true;
var context = new MyDbContext();
context.Database.EnsureCreated();
int? length = 1;
var result = context.Products.Where(p => p.Length == length).ToList();
length = null;
result = context.Products.Where(p => p.Length == length).ToList();
}
}
class MyDbContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseOracle(@"REDACTED");
}
public DbSet<Product> Products { get; set; }
}
class Product
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
public int? Length { get; set; }
}
Code: Select all
SELECT "p"."Id", "p"."Length", "p"."Name"
FROM "Products" "p"
WHERE (((("p"."Length" = :p__length_0) AND NOT ("p"."Length" IS NULL OR :p__length_0 IS NULL)) OR ("p"."Length" IS NULL AND :p__length_0 IS NULL)) AND NOT ("p"."Length" IS NULL OR :p__length_0 IS NULL))
OR ("p"."Length" IS NULL AND :p__length_0 IS NULL)
Code: Select all
// when length value is not null
SELECT [p].[Id], [p].[Length], [p].[Name]
FROM [Products] AS [p]
WHERE [p].[Length] = @__length_0
// when length value is null
SELECT [p].[Id], [p].[Length], [p].[Name]
FROM [Products] AS [p]
WHERE [p].[Length] IS NULL
Code: Select all
length == null ? p.Length == null : p.Length == length