Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ickers committed Aug 5, 2019
0 parents commit 6d5af16
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Bb]in/
[Oo]bj/
.vscode
.vs
*.db
*.suo
*.user
*.userosscache
*.sln.docstates
62 changes: 62 additions & 0 deletions EFCoreCoalesceNotEqualQueryIssue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;

namespace EFCoreCoalesceNotEqualQueryIssue
{
public class Data
{
[System.ComponentModel.DataAnnotations.Required]
public int? Id { get; set; }

public int? TestId { get; set; }

public string Name { get; set; }
}

class TestDbContext : DbContext
{
private readonly ILoggerFactory loggerFactory;

public TestDbContext( ILoggerFactory loggerFactory )
{
this.loggerFactory = loggerFactory;
}

public DbSet<Data> Data { get; set; }

protected override void OnConfiguring( DbContextOptionsBuilder optionsBuilder )
{
base.OnConfiguring( optionsBuilder );
optionsBuilder.UseSqlite( new Microsoft.Data.Sqlite.SqliteConnection("Data Source=test.db") );
optionsBuilder.UseLoggerFactory( loggerFactory );
}
}

class Repro
{
static void Main( )
{
var context = new TestDbContext( new LoggerFactory( ).AddConsole( LogLevel.Debug ) );
if( context.Database.EnsureCreated( ) )
{
context.Data.Add( new Data { Name = "HasTestId", TestId = 123 } );
context.Data.Add( new Data { Name = "ZeroTestId", TestId = 0 } );
context.Data.Add( new Data { Name = "NullTestId", TestId = null } );

context.SaveChanges( );
}

var noMainLinked = context.Data.Where( o => (o.TestId ?? 0) != 0)
.Select( o => o.Name )
.ToList( );

var expected = new HashSet<string>( new [] { "HasTestId" } );
Debug.Assert( expected.SetEquals( noMainLinked ), "Failed to get expected data");
return;
}
}
}
31 changes: 31 additions & 0 deletions EFCoreCoalesceNotEqualQueryIssue.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFrameworks>netcoreapp2.0;netcoreapp2.1;netcoreapp2.2</TargetFrameworks>
<PreserveCompilationContext>true</PreserveCompilationContext>
<AssemblyName>test</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>test</PackageId>
<TypeScriptCompileBlocked>false</TypeScriptCompileBlocked>
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.2' ">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.*" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.2.*" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.2.*" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.*" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.1' ">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.*" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.1.*" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.1.*" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.*" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.0' ">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.*" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.*" />
<PackageReference Include="Microsoft.Extensions.Options" Version="2.0.*" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.0.*" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.0.*" />
</ItemGroup>
</Project>

0 comments on commit 6d5af16

Please sign in to comment.