开发者

Show Computed Property in Entity Framework and WPF UI

开发者 https://www.devze.com 2023-01-29 23:52 出处:网络
I have a Download Entity in my EF Data Model.Two of its properties, Size and BytesDownloaded, compute to give me the Progress property I\'ve created in the partial class:

I have a Download Entity in my EF Data Model. Two of its properties, Size and BytesDownloaded, compute to give me the Progress property I've 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 UI 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 Model (edmx), I have to notify the UI that it should update the ProgressBar. I thought I could do this like so:

partial void OnBytesDownloadedChanging(long value)
{
    ReportPropertyChanging("Progress");
}
partial开发者_如何学JAVA void OnBytesDownloadedChanged()
{
    ReportPropertyChanged("Progress");
} 

This compiles fine, but when I run the app and OnBytesDownloadedChanging/Changed are called, I get this exception on my call to ReportPropertyChanging/Changed:

The property 'Progress' does not have a valid entity mapping on the entity object. For more information, see the Entity Framework documentation.

I understand what the error message is saying, but I don't understand what I can do to actually accomplish my goal.

PS - What specific "documentation" are they even referring to? Sigh! If they're going to imply there is documentation for this error, why don't they just link me to the documentation instead of telling me to [pointlessly] try and find it?


Use OnPropertyChanged/Changing instead of ReportPropertyChanged/Changing. The On* methods only raise the event, whereas the Report* methods also mark the property as modified for change tracking.

0

精彩评论

暂无评论...
验证码 换一张
取 消