Skip to content

HasIndex returns the wrong type for owned entities #24005

@ChristopherHaws

Description

@ChristopherHaws

It looks like OwnedNavigationBuilder.HasIndex is returning the wrong type. I believe it should return IndexBuilder<TDependentEntity>. In the code sample below, I cannot IncludeProperties from the type since it is showing the parent type's properties.

public virtual IndexBuilder<TEntity> HasIndex([NotNull] Expression<Func<TDependentEntity, object>> indexExpression)

Include your code

public sealed class Blog {
    public int BlogId { get; set; }
    public string Name { get; set; } = default!;

    public ICollection<Post> Posts { get; set; } = new HashSet<Post>();

    public sealed class Post {
        public int BlogId { get; set; }
        public int PostId { get; set; }
        public string Name { get; set; } = default!;
        public DateTime PostedDate { get; set; }
    }

    internal class EntityConfiguration : IEntityTypeConfiguration<Blog> {
        public void Configure(EntityTypeBuilder<Blog> entity) {
            entity.ToTable(nameof(Blog));
            entity.HasKey(x => x.BlogId).IsClustered();

            entity.OwnsMany(x => x.Posts, post => {
                post.ToTable(nameof(Post));
                post.HasKey(x => x.PostId).IsClustered();
                post.HasIndex(x => x.BlogId).IncludeProperties(x => x.PostedDate); // This line has build errors
            });
        }
    }
}

image

Include provider and version information

EF Core version: 5.0.1
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 5.0
Operating system: Windows 10
IDE: Visual Studio 2019 16.8.4

Metadata

Metadata

Assignees

No one assigned

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions