I have an Entity Framework 6.1.3 Code First data access library with C# and .NET Framework 4.7.
I have these two tables:
public class AggregationChildren
{
public int AggregationChildrenId { get; set; }
public int AggregationId { get; set; }
public int Position { get; set; }
public virtual Aggregation Aggregation { get; set; }
public virtual Code Code { get; set; }
}
public class Code
{
public int CodeId { get; set; }
public string Serial { get; set; }
[ ... ]
public virtual AggregationChildren AggregationChild { get; set; }
[ ... ]
}
And their configurations files:
class AggregationChildrenConfiguration : EntityTypeConfiguration<AggregationChildren>
{
public AggregationChildrenConfiguration()
{
HasKey(ag_ch => ag_ch.AggregationChildrenId);
HasRequired(ag_ch => ag_ch.Aggregation)
.WithMany(ag => ag.AggregationChildren)
.HasForeignKey(ag_ch => ag_ch.AggregationId);
HasRequired(ag_ch => ag_ch.Code)
.WithOptional(c => c.AggregationChild)
.WillCascadeOnDelete(false);
}
}
class CodeConfiguration : EntityTypeConfiguration<Code>
{
public CodeConfiguration()
{
HasKey(c => c.CodeId);
[ ... ]
}
}
I'm trying to set here that if there data in AggregationChildren
there must be the same data (AggregationChildrenId
== CodeId
) in Code
table, but the data in CodeId
could not be in AggregationChildren
table.
My question is: Is it need it the following configuration in AggregationChildrenConfiguration
class?
HasRequired(ag_ch => ag_ch.Code)
.WithOptional(c => c.AggregationChild)
.WillCascadeOnDelete(false);