2013-12-11 65 views
0

你好的基數所有(對不起我的英文不好), 我有一個奇怪的問題:我在LightSitch 2012(LS)使用WCF RIA服務。 使用WCF RIA編譯的類庫,我可以在LS中使用新的數據源。 我能夠導入的表和正確地看到(導航屬性表之間的關係,但是當我編譯整個解決方案我得到這個錯誤:WCF RIA LightSwitch中:社區

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.

現在唯一的解決辦法是註釋的協會第二類(TappaEntity),但我沒有嘗試使用表和我exprected錯誤.. 婁我寫我的code..can有人幫幫我好嗎? 非常感謝!

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; }   
} 
+0

我找到了解決方案,出現了問題,爲什麼我嘗試將PK與PK聯繫起來。 在類TappaEntity中,我使用了一個新的屬性int? PartentID作爲PK – Luca

+0

...等待代碼...我沒有足夠的聲望點:-( – Luca

+0

在類TappaEntity中,我使用了一個新的屬性int?PartentID作爲FK – Luca

回答

0

O找到答案...看下面的代碼

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; } 

}