DisplayFormat is not working on computed property in EF Core

80 views Asked by At

I have this computed property in my class called 'ProcessingTime', which is calculated based on other properties.

[Display(Name = "Processing Time (BD)")]
[DisplayFormat(DataFormatString = "{0:G0} business days")]
[NotMapped]
public int? ProcessingTime
{
    get
    {
        if (FirstSubmissionDate == null)
        {
            DateTime thisDay = DateTime.Today;
            return GetNumberOfWorkingDays(RegistrationDate, thisDay);

        } else
        {
            return GetNumberOfWorkingDays(RegistrationDate, (DateTime)FirstSubmissionDate);
        }


    }
    set { }
}

private static int GetNumberOfWorkingDays(DateTime start, DateTime stop)
    {
        int days = 0;
        while (start <= stop)
        {
            if (start.DayOfWeek != DayOfWeek.Saturday && start.DayOfWeek != DayOfWeek.Sunday)
            {
                ++days;
            }
            start = start.AddDays(1);
        }
        return days;
    }

In my view, the DisplayFormat is ignored and it's only showing a number. I want it to show ex. '5 business days'

Is there a way to achieve this?

UPDATE: I figured out that it's working fine, but the DataFormat is not showing up in my Bootstrap-Table.

1

There are 1 answers

0
vlatro On

I figured out that it's working fine, but the DataFormat is not showing up in my Bootstrap-Table.

This is because the data is sent to the table with json, so it looses its formatting...