【发布时间】:2010-12-12 19:37:10
【问题描述】:
我的 EF 数据模型中有一个下载实体。它的两个属性 Size 和 BytesDownloaded 计算得出我在分部类中创建的 Progress 属性:
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)));
}
}
}
在我的 WPF UI 中,我有:
<DataGridTemplateColumn x:Name="progressColumn" Header="Progress" Width="*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ProgressBar Value="{Binding Path=Progress, Mode=OneWay}" Maximum="100" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
由于 Progress 不是实体模型 (edmx) 的一部分,我必须通知 UI 它应该更新 ProgressBar。我以为我可以这样做:
partial void OnBytesDownloadedChanging(long value)
{
ReportPropertyChanging("Progress");
}
partial void OnBytesDownloadedChanged()
{
ReportPropertyChanged("Progress");
}
这编译得很好,但是当我运行应用程序并调用 OnBytesDownloadedChanging/Changed 时,我在调用 ReportPropertyChanging/Changed 时收到此异常:
属性“进度”没有 实体上的有效实体映射 目的。有关详细信息,请参阅 实体框架文档。
我理解错误消息的含义,但我不明白我可以做些什么来真正实现我的目标。
PS - 他们甚至指的是什么具体的“文档”?叹!如果他们要暗示有此错误的文档,他们为什么不直接将我链接到文档,而不是告诉我[毫无意义地]尝试找到它?
【问题讨论】:
标签: c# wpf entity-framework inotifypropertychanged