2

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 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?

1 Answer 1

3

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.

2
  • Thomas, thanks, but I guess I'm confused now. There are no 'OnProgressChanging/Changed' auto-generated functions that I can call because the Progress property is not in my data model. All it is is that public getter that is in the question. Is there someway to set up a computed property in my EF data model?
    – Chad
    Dec 13, 2010 at 14:21
  • 1
    They're not generated, they're inherited from the base class. Just call OnPropertyChanged("Progress"). Actually you probably don't need to call OnPropertyChanging, AFAIK it's only used for change tracking, not by WPF bindings Dec 13, 2010 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.