实体数据网格:添加计算值的最佳方式?
我有一个 WPF 数据网格数据绑定到 CollectionViewSource,它本身基于实体查询
在我的网格中,例如,我有 3 列 Number1、Number2、Number3,它们是实体的所有属性。如果我想添加一个名为 SumNumber 的列,它等于 Number1+Number2+Number3,那么最好的方法是什么,以便当我更改 Number1 时,SumNumber 中的值会更新?
提前致谢,
我已经快到了,但我又收到了另一个错误。请参阅下面的一段
public partial class MyEntity
{
public double MyCustomizedProperty{get;set;}
public MyEntity()
{
this.PropertyChanged += Entity_PropertyChanged;
}
void Entity_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName )
{
case "Date" :
MyCustomizedProperty = DateTime.Now.Second;
ReportPropertyChanged("MyCustomizedProperty");
break;
}
}
}
可编译的代码片段,但是当我更改“日期”时,我收到运行时错误:
The property 'SigmaFinal' does not have a valid entity mapping on the entity object. For more information, see the Entity Framework documentation.
我想这是因为该属性不在 OnStateManager 中。你能让我知道如何解决这个问题吗?
谢谢
I have a WPF datagrid databound to a collectionviewsource, which is itself based of a entity query
In my grid for example I have 3 columns Number1, Number2, Number3, all properties of an entity. If I want to add a column called SumNumber which is equal to Number1+Number2+Number3, what is the best way to do that so that when I change Number1, the value in SumNumber is updated ?
Thanks in advance
I'm almost there but I'm getting another error. See below a snippet of code
public partial class MyEntity
{
public double MyCustomizedProperty{get;set;}
public MyEntity()
{
this.PropertyChanged += Entity_PropertyChanged;
}
void Entity_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName )
{
case "Date" :
MyCustomizedProperty = DateTime.Now.Second;
ReportPropertyChanged("MyCustomizedProperty");
break;
}
}
}
That compiles and all, but when I change "Date" I get a runtime error :
The property 'SigmaFinal' does not have a valid entity mapping on the entity object. For more information, see the Entity Framework documentation.
I suppose this is due to the fact that the property is not in the OnStateManager. Can you please let me know how to fix that ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我要么创建一个
Converter
来获取所有 3 个值并返回它们的总和,要么扩展 Entity Framework 类以包含额外的属性下面是扩展 EF 类以包含额外财产:
I would either create a
Converter
that would take all 3 values and return the sum of them, or I would expand the Entity Framework class to include an extra propertyHere's an example of expanding the EF class to include the extra property: