-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6d5af16
Showing
3 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |