当我启用Fody自动生成Catel属性然后运行我的应用程序时,我收到一个运行时错误,说我的一个属性(引用另一个实体)无效:
财产'对冲'无效(不可序列化?)
当我尝试启用LeanAndMeanModel标志时,会发生在我的EntityBase的构造函数中。引用的实体为null,这是有效的,因为不需要对冲属性。
以下是相关代码:
[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
// ...
// ...
// ...
}