Show computed property in Entity Framework and WPF UI

I have a Download Entity in my EF data model. Two of its properties, Size and BytesDownloaded, are calculated to give me the Progress property that I created in the partial class:

partial class Download
{
    public int Progress
    {
        get
        {
            if (!Size.HasValue || Size.Value == 0) return 0;
            return Convert.ToInt32(Math.Floor(100.0 * ((double)BytesDownloaded / (double)Size)));
        }
    }
}

In my WPF interface, I have:

<DataGridTemplateColumn x:Name="progressColumn" Header="Progress"  Width="*">
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <ProgressBar Value="{Binding Path=Progress, Mode=OneWay}" Maximum="100" />
       </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

Since Progress is not part of the Entity (edmx) model, I have to notify the user interface that it needs to update the ProgressBar. I thought I could do it like this:

partial void OnBytesDownloadedChanging(long value)
{
    ReportPropertyChanging("Progress");
}
partial void OnBytesDownloadedChanged()
{
    ReportPropertyChanged("Progress");
} 

This compiles fine, but when I launch the application and OnBytesDownloadedChanging / Changed is called, I get this exception when I call ReportPropertyChanging / Changed:

"" . . Entity Framework.

, , , .

PS - "" ? ! , , , [] ?

+2
1

OnPropertyChanged/Changing ReportPropertyChanged/Changing. On* , Report* , .

+3

Source: https://habr.com/ru/post/1779407/


All Articles