2017-12-30 25 views
0

대다수의 관계 테이블을 보유하고 있습니다. SUBE 및 사용자엔티티에 대한 대다수 관계 테이블 쿼리 MVC

namespace Odev.Entities 
    { 
    public class User 
    { 
    [Key] 
    public int Id { get; set; } 
    [Required] 
    [DisplayName("Kimlik No")] 

    [ StringLength(11)] 
    [Index(IsUnique = true)] 
    public string UserName { get; set; } 

    [ StringLength(8)] 
    [DisplayName("Şifre")] 
    public string Password { get; set; } 

    [DisplayName("Ad Soyad")] 
    public string NameSurname { get; set; } 

    [DisplayName("Bölüm")] 
    public string Bolum { get; set; } 

    [DisplayName("Dal")] 
    public string Dal { get; set; } 

    [DisplayName("Öğrenci No")] 
    public int OgrenciNo { get; set; } 

    public int RoleId { get; set; } 
    public virtual ICollection<Sube> Subes { get; set; } 
    public virtual List<Notification> Notifications { get; set; } 
    public virtual List<Homework> Homeworks { get; set; } 
    public virtual Role Role { get; set; } 
    } 
} 

namespace Odev.Entities 
    { 
    public class Sube 
    { 
    [Key] 
    public int Id { get; set; } 

    [DisplayName("Şube")] 

    public string Sube_Name { get; set; } 
    public virtual Homework Homework { get; set; } 
    public virtual ICollection<User> Users { get; set; } 
    } 
} 

namespace Odev.DataAccessLayer 
    { 
    public class DatabaseContext : DbContext 
    { 
    public DatabaseContext() : base("dataConnection") 
    { 
     Database.SetInitializer(new OdevInitializer()); 
    } 
    public DbSet<User> Users { get; set; } 
    public DbSet<Homework> Homeworks { get; set; } 
    public DbSet<Role> Roles { get; set; } 
    public DbSet<Sube> Subes { get; set; } 
    public DbSet<Notification> Notifications { get; set; } 

    protected override void OnModelCreating(DbModelBuilder modelBuilder) 
    { 
     modelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); 
    } 
}  
} 

내 뷰 모델

namespace Odev.Models{ 
public class ViewModel{ 
public string Sube_Name { get; set; } 
public string NameSurname { get; set; } 
public string UserName { get; set; } 
public int UserId { get; set; } 
public int SubeId { get; set; } 
public User User { get; set; } 
public Sube Sube { get; set; } 
public Role Role { get; set; } 
}} 

나는 사용자의 SubeId을 보여주고 싶은 :

나는 SUBE의 ID를 선택하는 방법

enter image description here

?

답변