-
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
Update from ef 6 to ef 7. Error getting base type entities where one child has a required navigation property #31107
Labels
area-query
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
regression
type-bug
Milestone
Comments
Note for triage: still fails on latest daily. Minimal repro: using (var context = new SomeDbContext())
{
await context.Database.EnsureDeletedAsync();
await context.Database.EnsureCreatedAsync();
context.Add(new Child2Entity { Id = Guid.NewGuid(), Name = "Name" });
context.SaveChanges();
context.Set<BaseEntity>().ToList();
}
using (var context = new SomeDbContext())
{
}
public class SomeDbContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseSqlServer(@"Data Source=(LocalDb)\MSSQLLocalDB;Database=AllTogetherNow")
.LogTo(Console.WriteLine, LogLevel.Information)
.EnableSensitiveDataLogging();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<BaseEntity>();
modelBuilder.Entity<Child1Entity>(b =>
{
b.OwnsOne(entity => entity.Data, builder =>
{
builder.ToTable("Child1EntityData");
builder.WithOwner().HasForeignKey("Child1EntityId");
});
});
modelBuilder.Entity<Child2Entity>();
}
}
public abstract class BaseEntity
{
public Guid Id { get; set; }
public string Name { get; set; }
}
public sealed class Child1Data
{
public Guid Id { get; set; }
public string Name { get; set; }
}
public sealed class Child1Entity : BaseEntity
{
public Child1Data Data { get; private set; } = null!;
}
public sealed class Child2Entity : BaseEntity
{
} Output:
|
ajcvickers
changed the title
Migration error from ef 6 to ef 7. Error getting base type entities where one child has a required navigation property
Update from ef 6 to ef 7. Error getting base type entities where one child has a required navigation property
Jul 8, 2023
AndriySvyryd
added
the
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
label
Oct 3, 2023
AndriySvyryd
added a commit
that referenced
this issue
Oct 3, 2023
AndriySvyryd
added a commit
that referenced
this issue
Oct 3, 2023
AndriySvyryd
added a commit
that referenced
this issue
Oct 4, 2023
ajcvickers
pushed a commit
that referenced
this issue
Oct 4, 2023
AndriySvyryd
added a commit
that referenced
this issue
Oct 4, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
area-query
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
regression
type-bug
Bug
Retrieving entities of the base type where one child has a required navigation property throws a
SqlNullValuException
. Because not all entities have a required navigation property.Property.IsNullable
is expected to be true when reading properties navigation.Source code
Stack traces
Verbose output
Need to run test
Temporary solution
Have options:
<entityBuilder>.Metadata.IsRequiredDependent = false;
to navigation configurationProvider and version information
EF Core version: 7.0.5
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 6.0
The text was updated successfully, but these errors were encountered: