2

当我启用 Fody 自动生成 Catel 属性然后运行我的应用程序时,我收到一个运行时错误,说我的一个属性(它引用另一个实体)无效:

属性“对冲”无效(不可序列化?)

当我尝试启用 LeanAndMeanModel 标志时,这发生在我的 EntityBase 的构造函数中。引用的实体为空,这是有效的,因为不需要对冲属性。

以下是相关代码:

[DataContract]
public class EntityBase : ModelBase, IEntityBase
{
    public EntityBase()
    {
        LeanAndMeanModel = true;
        Id = ContextTools.GenerateComb();
    }
    [Column(Order = 0)]
    [Required, Key, DataMember]
    public Guid Id { get; set; }

    // For Row Level Concurrency
    [Column(Order = 2)]
    [Timestamp, DataMember]
    public Byte[] RowVersion { get; set; }

    /// <summary>
    /// Called after loading objects using Entity Framework
    /// to improve performance and enable proper function
    /// of Catel ModelBase features.
    /// 
    /// https://catelproject.atlassian.net/wiki/display/CTL/Using+ModelBase+as+base+for+entities
    /// 
    /// https://catelproject.atlassian.net/wiki/display/CTL/Performance+considerations
    /// 
    /// </summary>
    public void PostLoadSetup()
    {
        IsDirty = false;
        LeanAndMeanModel = false;
    }
}

[DataContract]
public class TransactionalBase :EntityBase, ITransactionalBase
{
    // Convenience field to make querying
    // for specific rows easier on the Database Side
    [Column(Order = 1), DataMember]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int RowNumber { get; set; }
}


[DataContract]
public class Trade : TransactionalBase, ITrade
{
    // Foreign Key
    [DataMember]
    public Guid? HedgeId { get; set; }

    // Navigation Property
    [DataMember]
    public Hedge Hedge { get; set; }

    [DataMember, Required]
    public DateTime TradeDate { get; set; }

    [DataMember, Required]
    public DateTime SettleDate { get; set; }

    // More properties follow
    // ...
    // ...
    // ...
}

[DataContract]
public class Hedge : TransactionalBase, IHedge
{
    [DataMember, Required]
    public DateTime HedgeDate { get; set; }

    [DataMember, Required]
    public DateTime SettleDate { get; set; }

    [DataMember, Required]
    public PurchaseType BuySell { get; set; }

    // Navigation property
    public virtual List<Trade> HedgedTrades { get; set; }

    // More properties follow
    // ...
    // ...
    // ...
}
4

0 回答 0