2016-10-16 4 views
2

可能かどうか:コレクションの友人であるエンティティのユーザーコンテンツICollectionユーザーが同じユーザーから構成されている場合は、メッセンジャーですか? 可能であれば、DbContextファイルで正しい関係を作成する方法を教えてください。 またはこの関係をいかにうまく構築するか。別のエンティティを作成できますか? ありがとうございます!あなたは正しい方向に向かっているICollectionユーザーを同じエンティティに追加するユーザー

namespace Tinkl.Data.Core.Domain 
{ 
    public class User 
    { 
     public User() 
     { 
      Contacts = new List<User>(); 
      Conversations = new List<Conversation>(); 
      Invites = new List<User>(); 
     } 

     public int UserId { get; set; } 
     public string NickName { get; set; } 
     public string EMail { get; set; } 
     public string Password { get; set; } 
     public DateTime? CreationDate { get; set; } 
     public DateTime? ExitDate { get; set; } 
     public string Picture { get; set; } 
     public string Status { get; set; } 
     public virtual ICollection<User> Invites { get; set; } 
     public virtual ICollection<User> Contacts { get; set; } 
     public virtual ICollection<Conversation> Conversations { get; set; } 
    } 
} 
+0

問題:すべてのユーザーのためのcreateв一つだけ共通のコレクションを –

答えて

1

は、することができますdbContextで同じ使用「OnModelCreating、私はseprate設定ファイルを作成していた

public class ContentEntityRef : BaseModel 
{ 
    public ContentEntityRef() 
    { 
     RoleRefs = new HashSet<RoleRef>(); 
    } 

    public int EntityId { get; set; } 

    public string EntityName { get; set; } 

    public int? ParentEntityId { get; set; } 

    public virtual ICollection<RoleRef> RoleRefs { get; set; } 

    public virtual ContentEntityRef Parent { get; set; } 

    public virtual ICollection<ContentEntityRef> Children { get; set; } 
} 

最初のEFコード内の自己関係の私の次のコードと同じタイプを参照してください" 方法。

internal class ContentEntityRefConfiguration : EntityTypeConfiguration<ContentEntityRef>, IEntityConfiguration 
{ 
    public ContentEntityRefConfiguration() 
    { 
     this.HasKey(x => x.EntityId).Property(t => t.EntityId).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity); 
     this.Property(x => x.EntityName).IsRequired().HasMaxLength(50); 

     this.HasMany(c => c.Children).WithOptional(c => c.Parent).HasForeignKey(c => c.ParentEntityId); 

     this.HasMany<RoleRef>(role => role.RoleRefs) 
      .WithMany(content => content.ContentEntities) 
      .Map(contentRole => 
      { 
       contentRole.MapLeftKey("EntityID"); 
       contentRole.MapRightKey("RoleID"); 
       contentRole.ToTable("RoleEntityMap"); 
      }); 
    } 
} 

これはあなたを助けることを願っています:)

関連する問題