Closed zoriya closed 11 months ago
I would REALLY love this feature as well.
I'd probably called this "Materialized Projectioables".
I would like the ability to optionally include a projectable property so that it's projected into the primary entity when it's loaded so that I don't need the related data to be included on the entity without having to include the related data.
Take this example:
public class MyEntity
{
public Guid Id { get; set; }
public MyOtherEntity MyOtherEntity { get; set; } = null!;
public Guid MyOtherEntityId { get; set; }
[Projectable(UseMemberBody(nameof(MyOtherEntityName))
public string MyOtherEntityNameIncluded { get; set; }
[Projectable] public string MyOtherEntityName => this.MyOtherEntity.Name;
}
public class MyOtherEntity
{
public Guid Id { get; set; }
public string Name { get; set; }
... a lot of other properties and potentially nested owned relationships so loading this entity is expensive
}
dbContext.DbSet<MyEntity>.Include(_ => _.MyOtherEntityNameIncluded)
// or maybe something custom
dbContext.DbSet<MyEntity>.Materialize(_ => _.MyOtherEntityNameIncluded)
If I don't have the materialized properties, I would have to o:
dbContext.DbSet<MyEntity>.Include(_ => _.MyOtherEntity)
which is extremely inefficient
When #86 gets merged, you would not need anything for your .MyOtherEntityNameIncluded
to work.
dbContext.DbSet<MyEntity>.First()
would already include your MyOtherEntityNameIncluded
.
Assuming this example:
I would like this to work:
with a generated query like that:
Right now, this example fails because the generated query is never rewritten. The actual query looks like this:
So the SQL provider throws because computed1 is not a valid column.