0

我有一个ObservableCollection实体框架 4 实体绑定到一个ListView. 如果我修改实体的任何正常的标量属性,则显示的值会ListView更新。

任何关系(导航)属性在ListView更改时都不会更新,因为实体对象不会为这些属性实现更改通知。

现在,我正在从集合中删除实体,然后将其重新插入到同一位置以强制ListView更新。

必须有更好的解决方案。它是什么,如果它存在的话?

这是 VS2010 的 EF 设计器生成的代码:

[EdmEntityTypeAttribute(NamespaceName="RovingAuditDb", Name="AuditRecord")]
[Serializable()]
[DataContractAttribute(IsReference=true)]
public partial class AuditRecord : EntityObject
{
    #region Factory Method

    /// <summary>
    /// Create a new AuditRecord object.
    /// </summary>
    /// <param name="id">Initial value of the Id property.</param>
    /// <param name="date">Initial value of the Date property.</param>
    public static AuditRecord CreateAuditRecord(global::System.Int32 id, global::System.DateTime date)
    {
        AuditRecord auditRecord = new AuditRecord();
        auditRecord.Id = id;
        auditRecord.Date = date;
        return auditRecord;
    }

    #endregion
    #region Primitive Properties
    // Deleted for this post
    #endregion

    #region Navigation Properties

    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    [XmlIgnoreAttribute()]
    [SoapIgnoreAttribute()]
    [DataMemberAttribute()]
    [EdmRelationshipNavigationPropertyAttribute("RovingAuditDb", "AuditRecordCell", "Cell")]
    public Cell Cell
    {
        get
        {
            return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Cell>("RovingAuditDb.AuditRecordCell", "Cell").Value;
        }
        set
        {
            ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Cell>("RovingAuditDb.AuditRecordCell", "Cell").Value = value;
        }
    }
    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    [BrowsableAttribute(false)]
    [DataMemberAttribute()]
    public EntityReference<Cell> CellReference
    {
        get
        {
            return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Cell>("RovingAuditDb.AuditRecordCell", "Cell");
        }
        set
        {
            if ((value != null))
            {
                ((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedReference<Cell>("RovingAuditDb.AuditRecordCell", "Cell", value);
            }
        }
    }
    // Rest of the Navigation properties removed for this post
4

1 回答 1

1

这些实体不适用于基于INotifyPropertyChanged. 我建议您看一下Self Tracking Entities,它最适合在客户端/服务器类型的 WPF 应用程序中使用。

于 2013-01-18T18:13:27.253 回答