I have a more complicated question here
But thought I would simplify it.
Here are my dummied classes (the structure this is based on comes from the NDC so I don't have control over it):
public class RightHand
{
[Key]
public int RightHandId { get; set; }
public string PropertyA { get; set; }
[Required]
public virtual Linker Linker { get; set; }
}
public class LeftHand
{
[Key]
public int LeftHandId { get; set; }
public string PropertyB { get; set; }
[Required]
public virtual Linker Linker { get; set; }
}
public class Linker
{
[Key]
public int LinkerId { get; set; }
[ForeignKey("RightHand")]
public int RightHandId { get; set; }
[ForeignKey("LeftHand")]
public int LeftHandId { get; set; }
public string PropertyC { get; set; }
[Required]
public virtual RightHand RightHand { get; set; }
[Required]
public virtual LeftHand LeftHand { get; set; }
}
I've tried so many things so hopefully this simplified version can help someone help me.
Over all, I want to search on:
- LeftHand.PropertyB and see the properties for RightHand
- As well, I want to search on RightHand.PropertyA and see the properties for Left Hand
All in all, I don't care about Linker except that is what links LeftHand to RightHand. LeftHand and RightHand are one-to-one.
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<RightHand>()
.Property(x => x.RightHandId)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
modelBuilder.Entity<LeftHand>()
.Property(x => x.LeftHandId)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
modelBuilder.Entity<Linker>()
.Property(x => x.LinkerId)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
modelBuilder.Entity<Linker>()
.HasRequired(nus => nus.LeftHand)
;
modelBuilder.Entity<Linker>()
.HasRequired(nuu => nuu.RightHand)
;
}
Thanks, I am using VS2017, EF 6.2, Code First, SQL Server
I have tried different annotations but the one common error is:
Linker_LeftHand_Source: : Multiplicity is not valid in Role 'Linker_LeftHand_Source' in relationship 'Linker_LeftHand'. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be '*'.
Linker_RightHand_Source: : Multiplicity is not valid in Role 'Linker_RightHand_Source' in relationship 'Linker_RightHand'. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be '*'.
What is different here than other multiplicity answers is the middle linker table.