1

私は苦労している次のシナリオを持っています:

public class SegUser
{
      public string IdUser { get; set; }

      public List<SegRol> SegRoles { get; set; }

      public virtual List<SegApps> Apps{ get; set; }
}

public class SegRole
{
     public virtual int IdRole { get; set; }

     public virtual List<SegUer> SegUsers { get; set; }

    public virtual List<SegApp> Apps { get; set; }

}

public class SegApp
{
      public virtual int IdApp{ get; set; }

      public virtual List<SegUser> Users { get; set; }

      public virtual List<SegRole> Roles { get; set; }

}

私のデータベースには、これらの 3 つのテーブルと、3 つのエンティティ間の関係を確立するための 3 つの PK (エンティティごとに 1 つ) を持つ追加のテーブルがあります。

Entity Framework 5 fluent API でマッピングを実現するにはどうすればよいですか。

私はすでに試しました:

    private void MapSegUser()
    {
        //mapping of another fields

        entityConfiguration
            .HasMany(x => x.SegRoles)
            .WithMany(x => x.SegUsers)
            .Map(mc =>
            {
                mc.MapLeftKey("id_role");
                mc.MapRightKey("id_user");
                mc.ToTable("seg_users_roles");
            });

        entityConfiguration
            .HasMany(x => x.Apps)
            .WithMany(x => x.Users)
            .Map(mc =>
            {
                mc.MapLeftKey("id_app");
                mc.MapRightKey("id_user");
                mc.ToTable("seg_users_roles_apps");
            });

    }


   private void MapSegApp()
    {
        //mapping of another fields

          entityConfiguration
            .HasMany(x => x.Users)
            .WithMany(x => x.Apps)
            .Map(mc =>
            {
                mc.MapLeftKey("id_user");
                mc.MapRightKey("id_app");
                mc.ToTable("seg_users_roles_apps");
            });

    }


     private void MapSegRole()
    {
        //mapping of another fields

        entityConfiguration
            .HasMany(x => x.SegUsers)
            .WithMany(x => x.SegRoles)
            .Map(mc =>
            {
                mc.MapLeftKey("id_user");
                mc.MapRightKey("id_role");
                mc.ToTable("seg_users_roles");
            });
    }
4

0 に答える 0