'Navigating from an View Entity to standard entity-
I am using EF Core 5, and I have an indexed view that I am trying to include another entity so that I can extend the filtering i am doing.
What I have tried to do is below
public partial class Table : Entity<long>
{
public Beneficiary()
{
IndexedView = new HashSet<IndexedView>();
}
public string Name { get; set; }
public virtual ICollection<IndexedView> IndexedView { get; set; }
}
public partial class IndexView : Entity<long>
{
[Key]
public long othertableid { get; set; }
public long tableid { get; set; }
public Table Table { get; set; }
}
public class IndexedViewEntityMapper : IEntityTypeConfiguration<IndexedView>
{
public void Configure(EntityTypeBuilder<IndexedVIew> entity)
{
entity.HasKey(x => x.othertableidId);
entity.ToView("vw_activeFundraisingBeneficiariesForEvents");
entity.HasOne(e => e.table)
.WithMany(e => e.indexedview)
.HasForeignKey(e => e.table);
entity.Property(e => e.tableid).HasColumnName("tableid");
entity.Property(e => e.othertableid).HasColumnName("othertableId");
}
}
I am able to query/filter/sort against the IndexView entity, but when I try to .include the table entity the generated sql that's executed (captured by running a trace) doesn't add the inner join, though it DOES add an additional id on the select (which doesn't exist because no join is made).
I've been struggling to find other examples of this, so I'm not sure what I'm missing.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
