2016-07-01 17 views
0
[DataContract] 
public class Match 
{ 
    [DataMember] 
    public Guid Id { get; set; } 

    public virtual Tour Tour { get; set; } 

    [DataMember] 
    public DateTime DateMatch { get; set; } 


    public virtual Team Home { get; set; } 

    public virtual Team Guest { get; set; } 

    public virtual Result Result { get; set; } 
} 

[DataContract] 
public class Result 
{ 
    [DataMember] 
    public Guid Id { get; set; } 

    public virtual Match Match { get; set; } 
    public virtual List<Goal> Goals { get; set; } 

} 

をタイプ間の関連の主要な終了を決定することができません:私はエラーを得たとき、エンティティフレームワークでこれを行うにしようとしていたエンティティフレームワークで

Unable to determine the principal end of an association between the types 'OperationWithTeams.Result' and 'OperationWithTeams.Match'. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations.

+0

しかし、削除 パブリック仮想結果結果{取得した場合;セット; } working – Venedchuk

+0

データアノテーションを使用している場合は、これをあなたの 'Match'クラスに追加してください: ' [ForeignKey( "Result")] public Guid? ResultId {get;セット; } ' そして、あなたの' result'クラスに以下を追加してください: '[ForeignKey(" Match ")] パブリックGuid MatchId {get;セット; } ' これは、マッチに結果(NULL)がないことを許可します。許可しない場合は、疑問符(?)を取り除いて「ResultId」をnullにできません。 –

答えて

0

あなたのモデルは、循環参照を定義しているのでMatchResultの間で、ModelBuilderで明示的に必要な動作を定義する必要があります。

結果が一致なしでは存在できないと仮定すると、しかしマッチはマッチにプリンシパルを作成し、依存の結果、結果なしでは存在できます。

ModelBuilder.Entity<Match>().HasOptional(m => m.Result).WithRequired(r => r.Match); 
関連する問題