-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Empty DbSet throw System.NullReferenceException when accessed even with SingleOrDefault and similar #16942
Comments
Note for triage: repos in current nightly:
[Owned]
public class OwnedModel
{
[Column(nameof(RequiredField))]
[Required]
public string RequiredField { get; set; }
}
public class DummyModel
{
[Required]
[Key, Column(Order = 0)]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long Id { get; set; }
[Required]
public OwnedModel OwnedModel { get; set; }
}
public class BloggingContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseInMemoryDatabase("Test");
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder
.Entity<DummyModel>()
.HasKey(d => d.Id);
}
}
public class Program
{
public static async Task Main()
{
using (var context = new BloggingContext())
{
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
}
using (var context = new BloggingContext())
{
var id = 1;
var results = await context.Set<DummyModel>().SingleOrDefaultAsync(d => id == d.Id);
}
}
} |
There is owned entity which will generate eager loaded include. Includes are not working for InMemory yet. |
@smitpatel Which issue is tracking that? |
@smitpatel Should have guessed...but we might need something specific in 3.0. |
Created #16963 to track this in 3.0. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In previous stable EF Core version (2.2.6)
DbSet
s behaved differently. One could call SingleOrDefault/SingleOrDefaultAsync (both parameter-less and with a predicate) on an emptyDbSet
without raisingSystem.NullReferenceException
.My tests in this solution demonstrate it.
Steps to reproduce
Please take a look
EmptyDbSet
project in this solution andInMemoryTests.EmptyDbSet()
xUnit test.Further technical details
EF Core version: 3.0.0-preview7.19362.6
Database Provider: Microsoft.EntityFrameworkCore.InMemory
Operating system: any
IDE: Visual Studio 2019 16.2
The text was updated successfully, but these errors were encountered: