Skip to content

Translate Computed Properties #32276

Closed as not planned
Closed as not planned
@OsamaAlRashed

Description

@OsamaAlRashed

I have two tables, Request and State. In the Request table, I've defined a computed property CurrentStatus as follows:

public abstract class Request<TKey, TStatus>
    where TKey : IEquatable<TKey>
    where TStatus : struct, Enum
{
    private readonly List<State<TKey, TStatus>> _statuses = new();
    
    [NotMapped]
    public virtual TStatus? CurrentStatus
        => _statuses
            .OrderByDescending(x => x.DateSigned)
            .Select(x => x.Status)
            .FirstOrDefault();
}

Is there any way to translate the CurrentStatus property without the need to store it in the database explicitly or create a function? I'm looking for a solution that handles this calculation without requiring a database column and ensures efficient querying.

I've attempted to use "Computed columns," but they don't seem to support computations involving properties from other tables.

EF Core Version: 7
Database Provider: SQL Server

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions