WCF RIA in LightSwitch: cardinality of Association

311 views Asked by At

Hello to all (sorry for my bad english), I have a strange problem: I'm using a WCF RIA Service in LightSitch 2012 (LS). The Class Library with the WCF RIA compiles, and I'm able to use it a new Data Source in LS. I'm able to import the tables and correctly see the relationship between tables (Navigation Properties, BUT when I compile the whole Solution I get this error:

Multiplicity is not valid in Role 'TappaEntity' in relationship 'AssocTappe'. Because the Dependent Role refers to the key properties, the upper bound of the multiplicity of the Dependent Role must be 1.

Right now the only solution is the comment the Association in the second class (TappaEntity), but I didn't try to use the Tables and I'm exprected errors.. Bellow I write my code..can someone help me please? Thanks a lot!!!

public class GiroEntity
{
   [Key(), Editable(false)]
    public int IdGiro { get; set; }

    [Required(ErrorMessage = "La descrizione del giro e' obbligatoria"), Editable(false), StringLength(50)]
    public string DescrizioneGiro { get; set; }

    [Include]
    [Association("AssocTappe", "IdGiro", "IdTappa", IsForeignKey = false)]
    public IQueryable<TappaEntity> Tappe { get; set; }
}

public class TappaEntity
{
    [Key(), Editable(false)]
    public int IdTappa { get; set; }

    [Required(ErrorMessage = "La descrizione della tappa e' obbligatoria"), Editable(false), StringLength(50)]
    public string DescrizioneTappa { get; set; }

    [Association("AssocTappe", "IdTappa", "IdGiro", IsForeignKey = true)]
    public GiroEntity Giro { get; set; }        
}
1

There are 1 answers

0
CodeTheCat On

O Found the answer...see the follow code

 public class GiroEntity
{
    [Key(), Editable(false)]
    public int IdGiro { get; set; }

    [Required(ErrorMessage = "La descrizione del giro e' obbligatoria"), Editable(false), StringLength(50)]
    public string DescrizioneGiro { get; set; }

    [Include]
    [Association("AssocTappe", "IdGiro", "ParentId", IsForeignKey = false)]
    //[Required(ErrorMessage = "Per il giro devono essere definite delle tappe")]
    public List<TappaEntity> Tappe { get; set; }
}

 public class TappaEntity
{
    [Key(), Editable(false)]
    public int IdTappa { get; set; }

    [Required(ErrorMessage = "La descrizione della tappa e' obbligatoria"), Editable(false), StringLength(50)]
    public string DescrizioneTappa { get; set; }

    public int? ParentId { get; set; }

    [Include]
    [Association("AssocTappe", "ParentId", "IdGiro", IsForeignKey = true)]
    public GiroEntity Giro { get; set; }

}