2017-01-31 12 views
1

多対多リレーションシップである必要がある3つのクラスがありますが、プロジェクトを実行するとEntity FrameworkはSQL Serverテーブル。私は移行を使用しました。コードファースト・エンティティ・フレームワークは、追加フィールドと多くの関係で動作しない可能性があります

私のユーザークラスはここにある:

[Table("tbl_User")] 
    public class User 
    { 
       public User() 
       { 
       } 

       #region Properties 
       [Key] 
       [Required][DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]    
       public long Id { get; set; }     
       public string FirstName { get; set; }    
       public string LastName { get; set; } 
       public string LoginName { get; set; } 
       public string Email { get; set; } 
       public string Password { get; set; } 
       public bool EmailVerify { get; set; } 
       public string Image { get; set; }    
       public DateTime CreateDate { get; set; } 
       public DateTime UpdateDate { get; set; } 
       public DateTime LoginDate { get; set; } 
       public bool Enabled { get; set; } 
       public bool Deleted { get; set; } 
       #endregion 

       #region Relations    
       public virtual IList<UserRole> UserRole { get; set; }   
       #endregion Relations 
    } 

役割のクラスはここにある:

[Table("tbl_Role")] 
public class Role 
{ 
     public Role() 
     { 
     } 

     #region Properties 
     [Key] 
     [Required] 
     [DatabaseGenerated(DatabaseGeneratedOption.Identity)]  
     public int Id { get; set; } 
     public string RoleName { get; set; } 
     public int Order { get; set; } 
     public string Icon { get; set; }     
     public DateTime CreateDate { get; set; } 
     public DateTime UpdateDate { get; set; }   
     public bool Enable { get; set; }  
     public bool Deleted { get; set; } 
     #endregion Properties 

     #region Relations      
     public virtual IList<UserRole> UserRole { get;set;} 


     #endregion Relations 
} 

UserRoleがある私の多対多の関係テーブル:ここで

[Table("tbl_UserRole")] 
public class UserRole 
{ 
      internal class Configuration : System.Data.Entity.ModelConfiguration.EntityTypeConfiguration<UserRole> 
      { 
       public Configuration() 
       { 
        HasRequired(current => current.User) 
         .WithMany(userrole => userrole.UserRole) 
         .HasForeignKey(fk => fk.UserId); 

        HasRequired(current => current.Role) 
         .WithMany(userrole => userrole.UserRole) 
         .HasForeignKey(fk => fk.RoleId); 
       } 
      } 

      public UserRole() 
      { 
      } 

      #region Properties 
      [Key] 
      [Required]    
      public long Id { get; set; }   
      public DateTime GrantDate { get; set; } 
      public DateTime ExpireDate { get; set; } 
      public bool Enabled { get; set; } 
      public bool Deleted { get; set; } 
      #endregion Properties 

      #region Relations 
      public long UserId { get; set; } 
      public virtual User User { get; set; } 
      public int RoleId { get; set; } 
      public virtual Role Role { get; set; } 
      #endregion Relations 
} 

と私のデータベースのコンテキスト

public class LiveMiracleDbContext:DbContext 
    { 
      public LiveMiracleDbContext() : base("LMConnection") 
      { 
      } 

      public DbSet<User> tbl_User { get; set; } 
      public DbSet<Role> tbl_Role { get; set; } 
      public DbSet<UserRole> tbl_UserRole { get; set; } 
    } 

これらのクラスを使用せずにプロジェクトを実行すると、データベースが生成されますが、これらのクラスを使用するとデータベースが生成されません。ゲルト・アーノルドのコメントを

+0

EFで生成されたSQLを確認するには、「データベースの更新 - データベース」を試してください。それを使用して問題をさらに追跡します。 – wertzui

+0

これらの 'TypeConverter'属性は何をすべきでしょうか?ちなみに、この属性のフォレストを読みやすさのために少しずつ整えるのは良い考えです。 –

+0

可読性のために属性を枝刈りした –

答えて

0

OKタンクは

問題は、このstracture iが属性を削除真

である私の属性にありました。

関連する問題