[英]Entity Framework Configuration Issues
我需要讓每個SimCompare具有兩個SimCompareSimulationTypes列表。
SimCompare:
public class SimCompare : Report
{
public string LeftGraphName { get; set; }
public int? LeftConsolidationId { get; set; }
public int LeftAsOfDateOffset { get; set; }
public virtual Consolidation LeftConsolidation { get; set; }
public virtual ICollection<SimCompareSimulationType> SimCompareLeftSimulations { get; set; }
public string RightGraphName { get; set; }
public int? RightConsolidationId { get; set; }
public int RightAsOfDateOffset { get; set; }
public virtual Consolidation RightConsolidation { get; set; }
public virtual ICollection<SimCompareSimulationType> SimCompareRightSimulations { get; set; }
public bool IsQuarterly { get; set; }
public virtual ICollection<SimCompareScenarioType> SimCompareScenarioTypes { get; set; }
}
SimCompareSimulationType:
public class SimCompareSimulationType
{
public int Id { get; set; }
public int SimCompareId { get; set; }
public virtual SimCompare SimCompare { get; set; }
public int SimulationTypeId { get; set; }
public virtual SimulationType SimulationType { get; set; }
public int Priority { get; set; }
}
當它嘗試創建SimCompare時,都不會創建任何集合。 有一個已全部注釋掉的映射文件,我不知道該怎么做。
//HasRequired(l => l.LeftSimCompareSimulationTypes)
// .WithMany()
// .HasForeignKey(t => t.LeftSimCompareSimulationTypeId)
// .WillCascadeOnDelete(false);
//HasRequired(l => l.RightSimCompareSimulationTypes)
// .WithMany()
// .HasForeignKey(t => t.RightSimCompareSimulationTypeId)
// .WillCascadeOnDelete(false);
有什么幫助嗎? 我對如何工作幾乎一無所知。
用lamemans術語來說,配置指定實體如何轉換為db表。 因此,為了使SimCompare
有集合SimCompareSimulationTypes
你需要更新配置。
首先使用代碼時,通常需要手動創建配置,會生成默認值,但我經常發現它們不能滿足我100%的要求。
只是出於興趣,您是否嘗試過運行注釋掉的代碼?
this.HasRequired(l => l.LeftSimCompareSimulationTypes)
.WithMany()
.HasForeignKey(t => t.LeftSimCompareSimulationTypeId)
.WillCascadeOnDelete(false);
我們的配置之一的示例。
public class SomeConfiguration: EntityTypeConfiguration<Some>
{
public SomeConfiguration()
{
// Property/column will have a max of 10 & will be required
this.Property(o => o.Code).HasMaxLength(10).IsRequired();
// Property/column will have a max of 50 & will be required
this.Property(o => o.Name).HasMaxLength(50).IsRequired().IsUnicode(false);
// will be nullable in the db, with a foreign key of ExchangeID
this.HasOptional(o => o.Exchange).WithMany().HasForeignKey(o => o.ExchangeId).WillCascadeOnDelete(false);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.