Skip to content

Translate Computed Properties #32276

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
OsamaAlRashed opened this issue Nov 11, 2023 · 1 comment
Closed

Translate Computed Properties #32276

OsamaAlRashed opened this issue Nov 11, 2023 · 1 comment

Comments

@OsamaAlRashed
Copy link

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

@roji
Copy link
Member

roji commented Nov 12, 2023

Duplicate of #10768

@roji roji marked this as a duplicate of #10768 Nov 12, 2023
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Nov 15, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

3 participants